我正在嘗試主題我的應用遵循材質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>
資源/值-V21 /風格.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會在可能的情況下模擬顏色主題。目前這僅限於着色動作欄和一些小部件。 http://android-developers.blogspot.in/2014/10/appcompat-v21-material-design-for-pre。html –
我在模擬器上運行API 24 –