所以,我有一个奇怪的问题:我的应用程序非常简单,主要活动只有一个按钮,并且清单中设置的活动的自定义主题。
我可以确认主题有效并被选中,因为我可以更改活动背景或字体颜色,例如
但是当我尝试为我的活动中的所有按钮设置样式时,它不起作用!
这是样式.xml我使用的代码:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:background">#0f0</item>
<item name="android:buttonStyle">@style/btxs</item>
</style>
<style name="btxs" parent="@android:style/Widget.Button">
<item name="android:textColor">#f00</item>
</style>
</resources>
活动的背景是绿色的(因此主题有效),但按钮仍然是默认的。
Is android:buttonStyle
在主题中设置按钮样式的正确方法?
作为参考,我也粘贴了我的活动主文件
<?xml version="1.0" encoding="utf-8"?>
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_below="@+id/textView"
android:layout_toEndOf="@+id/textView"
android:layout_marginTop="25dp" />
</RelativeLayout>
An AppCompatActivity
将使用buttonStyle
。我还假设您可能想延长Base.Widget.AppCompat.Button
.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:background">#0f0</item>
<item name="buttonStyle">@style/btxs</item>
</style>
<style name="btxs" parent="Base.Widget.AppCompat.Button">
<item name="android:textColor">#f00</item>
</style>
</resources>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)