当应用部分按钮的样式时,为按钮创建自定义样式。这是样式代码 fragment 。
list .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/>
我不明白代码中的错误是什么以及在哪里。
最佳答案
纠正按钮 android:theme
部分。
不要
android:theme="@style/back_button_style
做
style="@style/back_button_style"
然后Clean-Rebuild-Run
。
关于android - 自定义按钮样式部分应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45996652/