自定义按钮样式部分应用
创建自定义样式按钮时应用样式按钮它是部分。这是样式代码片段。自定义按钮样式部分应用
的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" />
applyin后g样式只有文本颜色更改为白色,因为我将文本颜色设置为白色样式,但其他凭据未应用背景,在应用按钮文本颜色为黑色之前。 所以我不明白为什么它部分应用风格。
我想这样也,但它不工作
<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/>
我没有得到什么和在哪里是在代码中的bug。
更正按钮android:theme
部分。
不要
android:theme="@style/back_button_style
做
style="@style/back_button_style"
然后Clean-Rebuild-Run
。
我也尝试过这样,但它是部分应用只应用文本颜色和边距,但背景和高度不适用,我通过在按钮上应用背景来单独检查它的工作原理 –
@ ArchanaSM'android:background' –
@ArchanaSM remove'android:layout_height =“wrap_content”'https://*.com/a/6608323/3395198 –
[如何使用XML样式在Android中创建自定义按钮]的可能重复(https://*.com/questions/18507351/how-to-create-custom-button-in-android-using-xml-styles ) – akhilesh0707
尝试'style =“@ style/back_button_style”''而不是'android:theme =“@ style/back_button_style”' – Joshua
'android:theme =“@ style/Appl_methods”' –