【发布时间】:2019-03-13 01:19:24
【问题描述】:
我想使用styles.xml 为布局中的按钮设置样式,如下所示。
styles.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>
</style>
<style name="SearchButton" parent="Widget.AppCompat.Button.Colored">
<item name="android:textColor">@color/white</item>
<item name="android:textSize">15sp</item>
<item name="colorButtonNormal">@color/colorPrimary</item>
</style>
并使用 android:theme 将此样式应用于按钮。
<Button
android:theme="@style/SearchButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="15dp"
android:text="@string/search_button_text" />
在预览窗口中,此代码不会对默认的灰色 Material Design 按钮进行任何更改。
额外:我尝试过使用“style=”,它会部分工作,但它会忽略 colorButtonNormal 并改用 AccentColor。
【问题讨论】:
标签: android android-button android-theme android-styles