【发布时间】:2017-02-11 22:38:12
【问题描述】:
我正在尝试为我的应用设置主题以遵循材料 Android 外观。我的项目是一个 Xamarin.Android 项目,它以 API 23 为目标,但最低 API 目标是 16。所以我必须使用 AppCompat 库在所有 API 上进行相同的设计。
我遵循了这些指南:Material Theme,Beautiful Material Design with the Android Support Design Library,Android Tips: Hello AppCompatActivity, Goodbye ActionBarActivity 并创建了这些文件:
-
资源/值/styles.xml:
<resources> <style name="MyTheme" parent="MyTheme.Base"> </style> <style name="MyTheme.Base" parent="Theme.AppCompat.Light"> <item name="colorPrimary">#F44336</item> <item name="colorPrimaryDark">#D32F2F</item> <item name="colorAccent">#FF4081</item> </style> </resources> -
资源/values-v21/styles.xml
<resources> <!-- Base application theme for API 21+. This theme replaces MyTheme from resources/values/styles.xml on API 21+ devices. --> <style name="MyTheme" parent="MyTheme.Base"> <item name="android:windowContentTransitions">true</item> <item name="android:windowAllowEnterTransitionOverlap">true</item> <item name="android:windowAllowReturnTransitionOverlap">true</item> <item name="android:windowSharedElementEnterTransition">@android:transition/move</item> <item name="android:windowSharedElementExitTransition">@android:transition/move</item> </style> </resources> -
MainActivity.cs
using Android.App; using Android.Widget; using Android.OS; using Android.Support.V7.App; namespace TestThemeApp { [Activity(Label = "TestThemeApp", MainLauncher = true, Icon = "@drawable/icon", Theme = "@style/MyTheme")] public class MainActivity : AppCompatActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); } } }
我只是想让工具栏变成红色,状态栏变成深红色,但状态栏颜色不会改变。这是它的样子:
我做错了什么?
【问题讨论】:
-
您正在测试的设备是什么 API 级别?我相信这仅适用于 API 21+ 设备。在旧平台上,AppCompat 尽可能模拟颜色主题。目前,这仅限于为操作栏和一些小部件着色。 android-developers.blogspot.in/2014/10/…
-
我在模拟器上运行 API 24
标签: android xamarin material-design android-appcompat