在Android的5按钮样式的工作,但不是安卓4.0 [英] Button style working in Android 5 but not Android 4
问题描述
我有一个蓝色的背景,在22 API工作正常,按钮样式,但同样的按钮会出现在暗灰色无的Android 4.本应用的风格就是我的风格:
I have a button style with a blue background that works fine in API 22, but the same button appears in dark grey without the applied style in Android 4. This is my style:
<style name="MyApp.Plain" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background</item>
<item name="android:buttonStyle">@style/MyApp.Widget.Button</item>
</style>
<style name="MyApp.Widget.Button" parent="@android:style/Widget.Button">
<item name="android:background">@drawable/btn_blue</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">14sp</item>
<item name="android:textColor">#fff</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
</style>
我btn_blue.xml
My btn_blue.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_disabled" android:state_enabled="false"/>
<item android:drawable="@drawable/btn_pressed" android:state_enabled="true" android:state_pressed="true"/>
<item android:drawable="@drawable/btn_normal_blue" android:state_enabled="true"/>
</selector>
和btn_normal_blue.xml
and btn_normal_blue.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#368ac6"
android:startColor="#0e58a4" />
<corners android:radius="20dp" />
</shape>
有什么能为这种现象的原因以及如何解决这一问题?
What could be the reason for this behavior and how can I fix this?
编辑:这不会支持V7工作:22.2.0,但是,与V7工作:21.0.3。我没有改变,除了依赖任何东西,改变AppCompatActivity到ActionBarActivity。
This does not work with support v7:22.2.0, but does work with v7:21.0.3. I didn't change anything besides the dependency and changed AppCompatActivity to ActionBarActivity.
可能这是一个Android的bug。
Possibly this is an Android bug.
推荐答案
尝试使用应用程序兼容性:
Try to use AppCompat:
<style name="MyApp.Widget.Button" parent="Base.TextAppearance.AppCompat.Button">
<item name="android:background">@drawable/btn_blue</item>
...
</style>
这篇关于在Android的5按钮样式的工作,但不是安卓4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!