nas*_*sch 9 android android-styles
我正在尝试设置我的样式,使所有按钮成为特定的颜色组合,特别是蓝色和白色文本.这是我的主要styles.xml:
<resources>
<style name="CustomTheme" parent="MaterialDrawerTheme.Light.DarkToolbar">
<!-- various items -->
<item name="android:buttonStyle">@style/ButtonStyle</item>
</style>
<!-- a couple of other styles -->
<style name="ButtonStyle" parent="android:style/Widget.Button">
<item name="android:textSize">19sp</item>
<item name="android:textColor">@color/primaryTextContrast</item>
<item name="android:background">@color/primary</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
在清单中:
<application
android:name=".CustomApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/application_name"
android:theme="@style/CustomTheme">
Run Code Online (Sandbox Code Playgroud)
color/primary是深蓝色,color/primaryTextContrast是白色的.在棒棒糖上,按钮看起来很完美.在4.1设备上,它是浅灰色和黑色文本.我发现这样做的每一个资源都与我正在做的完全一样,所以我不知道我在这里缺少什么.
我在基本样式定义中控制文本大小也遇到了类似的问题.
更新:这是颜色.
<resources>
<color name="primary">#3F51B5</color>
<color name="dark">#303F9F</color>
<color name="accent">#FFCA28</color>
<color name="background">@android:color/white</color>
<!-- Color for text displayed on top of the primary or dark color -->
<color name="primaryTextContrast">@android:color/white</color>
<!-- Color for text displayed on the background color (which I think will always be white) -->
<color name="basicText">@color/primary</color>
<!-- Color for text displayed on the accent color -->
<color name="accentText">#303F9F</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
这是v19/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="FullscreenTheme" parent="MaterialDrawerTheme.Light.DarkToolbar.TranslucentStatus">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
这是v21:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="CustomTheme">
<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)
我认为其中任何一个都不能使它在5.1上正常工作.
Raf*_*edo 13
使用AppCompat 22.1.+(也22.2.0应该工作),我定义了一个样式:
<style name="MyApp.Button.Red" parent="Base.Widget.AppCompat.Button">
<item name="colorButtonNormal">@color/primary</item>
<item name="android:colorButtonNormal">@color/primary</item>
<item name="android:textColor">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后使用命名空间中的native theme属性在一个按钮中应用主题android,如Chris Banes的这篇精彩帖子所述.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sign_up_button"
android:theme="@style/MyApp.Button.Red" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3798 次 |
| 最近记录: |