【发布时间】:2017-09-01 08:59:32
【问题描述】:
在部分应用按钮样式时为按钮创建自定义样式。这是样式代码sn-p。
Manifest.xml
<application android:theme="@style:AppTheme">
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:buttonStyle">@style/back_button_style</item>
<item name="buttonStyle">@style/back_button_style</item>
</style>
<style name="back_button_style" parent="Widget.AppCompat.Button">
<item name="background">@drawable/back_button_shape</item>
<item name="android:layout_height">40dp</item>
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textAlignment">center</item>
<item name="android:textAllCaps">true</item>
<item name="android:layout_marginStart">72dp</item>
<item name="android:layout_marginEnd">72dp</item>
<item name="android:fontFamily">sans-serif</item> //sans-serif nothing but robot regular
</style>
layout.xml
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="continue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.501"
android:layout_marginBottom="8dp" />
应用样式后,仅文本颜色变为白色,因为我在样式中将文本颜色设置为白色,但其他凭据未应用背景,在应用按钮文本颜色为黑色之前。 所以我不明白为什么它会部分应用该样式。
我也试过这样,但它不起作用
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="continue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.501"
android:layout_marginBottom="8dp"
android:theme="@style/back_button_style/>
我不知道代码中的错误是什么以及在哪里。
【问题讨论】:
-
试试
style="@style/back_button_style"而不是android:theme="@style/back_button_style" -
android:theme="@style/AppTheme" -
style="@style/back_button_style", yaa 我也试过这样,但它部分应用意味着只应用了文本颜色和边距,但背景和高度没有应用,我通过应用单独检查按钮上的背景它可以工作
标签: android xml button android-styles