按钮的Android主题样式不适用 [英] Android theme style for button not applying
本文介绍了按钮的Android主题样式不适用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的主要活动视图中有三个简单的按钮. 我想做的是将按钮样式应用于所有按钮,但我没有这样做.
I have three simple buttons in my main activity view. What I am trying to do is apply a buttonstyle to all my buttons but I fail to do so.
这是我的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/minecraft_portrait"
android:alpha="0.75"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/txtAppName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/app_name_readable"
android:textSize="32sp"
android:textColor="@android:color/white" />
<Button
android:id="@+id/btnCrafting"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/button_selector"
android:onClick="craftingButtonClicked"
android:text="@string/crafting" />
<Button
android:id="@+id/btnServerCommands"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/btnCrafting"
android:layout_below="@id/btnCrafting"
android:layout_marginTop="20dp"
android:background="@drawable/button_selector"
android:onClick="commandsButtonClicked"
android:textColor="@android:color/white"
android:text="@string/servercommands" />
<Button
android:id="@+id/btnVideos"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/btnServerCommands"
android:layout_below="@id/btnServerCommands"
android:layout_marginTop="20dp"
android:background="@drawable/button_selector"
android:onClick="videosButtonClicked"
android:text="@string/videos" />
</RelativeLayout>
这是res/values文件夹中的style.xml:
And this is my style.xml from the res/values folder:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:buttonStyle">@style/ButtonTheme</item>
</style>
<style name="ButtonTheme" parent="android:Widget.Button">
<item name="android:textColor">@android:color/white</item>
<item name="android:background">@android:color/darker_gray</item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">32sp</item>
</style>
</resources>
清单文件中的主题定义:
And my theme definition from the manifest file:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
....
有什么想法为什么风格不适用于我的按钮? 我将一个按钮的文本颜色设置为白色,只是为了看到任何区别.
Any ideas why the style isn't applying to my buttons? I have set the textcolor of one button to white just to see any difference.
推荐答案
在使用支持库时,按钮样式必须应用为:
When using the support library the button style must be applied as:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:buttonStyle">@style/ButtonTheme</item>
<item name="buttonStyle">@style/ButtonTheme</item>
</style>
注意重复项,但没有名称空间
Note the duplication but with no namespace
这篇关于按钮的Android主题样式不适用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文