Sha*_*aul 5 android colors material-design
我在http://android-developers.blogspot.in/2014/10/appcompat-v21-material-design-for-pre.html中为我的项目使用相同的代码.
当我创建一个仅测试工具栏的空白项目时,颜色正常工作.但是,使用相同的代码将项目升级到材料设计后,工具栏颜色变为灰色.
似乎android:background?attr/colorPrimary
没有加载正确的颜色.当我使用时@color\theme_red
,颜色在工具栏上正确设置.
这里出了什么问题?
我的colors.xml:
<?xml version="1.0" encoding="utf-8"?><resources>
<color name="theme_red">#d43d1e</color>
<color name="theme_red_dark">#aa3118</color>
<color name="theme_accent">#3333ff</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
&styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/theme_red</item>
<item name="colorPrimaryDark">@color/theme_red_dark</item>
<item name="colorAccent">@color/theme_accent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
和工具栏的代码:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
Run Code Online (Sandbox Code Playgroud)
工具栏的外观如下android:background?attr/colorPrimary
:
工具栏的外观如下
@color/theme_red
:
更新:我正在更新问题,因为我在代码中有另一个似乎有关的错误.我尝试在Android 5.0.2手机上使用该应用程序,即使在styles.xml中定义了正确的主题和颜色,状态栏也没有暗色调.状态栏Toolbar
与第一张图像中的颜色完全相同.
styles.xml在上面.v-21/styles.xml如下:
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="colorPrimary">@color/theme_red</item>
<item name="colorPrimaryDark">@color/theme_red_dark</item>
<item name="colorAccent">@color/theme_accent</item>
<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>
Run Code Online (Sandbox Code Playgroud)
不知何故,即使在正确定义之后,系统也无法使用这些颜色.
整个项目可在以下网址获得:https://github.com/pauldmps/BPUTApp-AndroidStudio,如果有人想查看整个代码.
您在清单中指定了错误的主题:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
Run Code Online (Sandbox Code Playgroud)
你应该使用android:theme="@style/AppTheme"
.
归档时间: |
|
查看次数: |
5213 次 |
最近记录: |