Android默认按钮样式不工作

前端之家收集整理的这篇文章主要介绍了Android默认按钮样式不工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图设置我的样式,使所有的按钮是一个特定的颜色组合,特别是蓝色与白色文本.这是我的主要styles.xml:
  1. <resources>
  2. <style name="CustomTheme" parent="MaterialDrawerTheme.Light.DarkToolbar">
  3. <!-- varIoUs items -->
  4.  
  5. <item name="android:buttonStyle">@style/ButtonStyle</item>
  6. </style>
  7.  
  8. <!-- a couple of other styles -->
  9.  
  10. <style name="ButtonStyle" parent="android:style/Widget.Button">
  11. <item name="android:textSize">19sp</item>
  12. <item name="android:textColor">@color/primaryTextContrast</item>
  13. <item name="android:background">@color/primary</item>
  14. </style>
  15. </resources>

在清单中:

  1. <application
  2. android:name=".CustomApplication"
  3. android:allowBackup="true"
  4. android:icon="@mipmap/ic_launcher"
  5. android:label="@string/application_name"
  6. android:theme="@style/CustomTheme">

color / primary是深蓝色,color / primaryTextContrast是白色的.在棒棒糖,按钮看起来完美.在4.1设备上,它是浅灰色的黑色文字.我发现这样做的每个资源看起来都像我在做什么,所以我不知道我在这里失踪了什么.

我也有类似的问题,控制基本样式定义中的文本大小.

更新:这里是颜色.

  1. <resources>
  2. <color name="primary">#3F51B5</color>
  3. <color name="dark">#303F9F</color>
  4. <color name="accent">#FFCA28</color>
  5. <color name="background">@android:color/white</color>
  6. <!-- Color for text displayed on top of the primary or dark color -->
  7. <color name="primaryTextContrast">@android:color/white</color>
  8. <!-- Color for text displayed on the background color (which I think will always be white) -->
  9. <color name="basicText">@color/primary</color>
  10. <!-- Color for text displayed on the accent color -->
  11. <color name="accentText">#303F9F</color>
  12. </resources>

这里是v19 / styles.xml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <style name="FullscreenTheme" parent="MaterialDrawerTheme.Light.DarkToolbar.TranslucentStatus">
  4. <item name="android:windowTranslucentNavigation">true</item>
  5. <item name="android:windowNoTitle">true</item>
  6. <item name="android:windowTranslucentStatus">true</item>
  7. </style>
  8. </resources>

这是v21:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <style name="AppTheme" parent="CustomTheme">
  4. <item name="android:windowContentTransitions">true</item>
  5. <item name="android:windowAllowEnterTransitionOverlap">true</item>
  6. <item name="android:windowAllowReturnTransitionOverlap">true</item>
  7. <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
  8. <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
  9. </style>
  10. </resources>

我不认为这些都是在5.1上正常工作的.

解决方法

使用AppCompat 22.1. (22.2.0也应该工作),我定义了一个这样的样式:
  1. <style name="MyApp.Button.Red" parent="Base.Widget.AppCompat.Button">
  2. <item name="colorButtonNormal">@color/primary</item>
  3. <item name="android:colorButtonNormal">@color/primary</item>
  4. <item name="android:textColor">@android:color/white</item>
  5. </style>

然后使用Android命名空间中的本机主题属性主题应用于按钮,如Chris Banes的this令人惊叹的帖子中所述.

  1. <Button
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:text="@string/sign_up_button"
  5. android:theme="@style/MyApp.Button.Red" />

猜你在找的Android相关文章