我已经检查了所有解决方案,但非我的情况。我无法理解为什么状态栏的颜色不会改变(默认为灰色) 在我定义的样式中:
<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#2e662f</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">#4CAEE3</item>
</style>
在AndroidManifest中:
<application android:label="App1" android:theme="@style/Theme.DesignDemo" android:icon="@drawable/icon">
在活动中,我这样打电话:
[Activity(Label = "", MainLauncher = true, Icon = "@drawable/icon")]
我也试过这样的事情:
[Activity(Label = "", Theme = "@style/Theme.DesignDemo",MainLauncher = true, Icon = "@drawable/icon")]
答案 0 :(得分:1)
确保在AndroidManifest.xml文件中设置android:targetSdkVersion
,或者如果您愿意,也可以使用代码。
您可以使用从Java翻译的以下代码以编程方式更改Xamarin Android应用的状态栏颜色:
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
// clear FLAG_TRANSLUCENT_STATUS flag:
Window.ClearFlags(Android.Views.WindowManagerFlags.TranslucentStatus);
//Window.ClearFlags(WindowManager.Pa WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
Window.AddFlags(Android.Views.WindowManagerFlags.DrawsSystemBarBackgrounds);
// finally change the color
Window.SetStatusBarColor(new Color(ContextCompat.GetColor(this, Resource.Color.colorPrimaryDark)));
}
确保您的主题使用Theme.AppCompat
样式,然后您的活动应继承自AppCompatActivity
。所以你应该有这样的东西:
[Activity(Label = "Dialogs Demo", MainLauncher = true, Icon = "@mipmap/icon", Theme = "@style/AppTheme")]
public class MainActivity : AppCompatActivity
{}
这样的样式:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>