2017-09-01 1 views
1

Erstellt benutzerdefinierten Stil für Schaltfläche, wenn Sie den Stil für Schaltfläche anwenden, ist es teilweise. Hier ist das Stil-Code-Snippet.Angepasster Button-Stil wird teilweise angewendet

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" /> 

Nach applyin g der Stil nur die Textfarbe ändert sich zu Weiß, da ich die Textfarbe als weiß in der Art gegeben habe, aber andere Anmeldeinformationen nicht Hintergrund angewendet werden, vor dem Anwenden der Knopftextfarbe war Schwarzes. Also ich verstehe nicht, warum es teilweise den Stil anwendet.

ich so auch versucht, aber es funktioniert nicht

<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/> 

ich nicht bekommen, was und wo der Fehler im Code ist.

+0

Mögliche Duplikate von [Wie benutzerdefinierte Schaltfläche in Android mit XML-Formatvorlagen erstellen] (https://stackoverflow.com/questions/18507351/how-to-create-custom-button-in-android-using-xml-styles) – akhilesh0707

+0

versuche 'style =" @ style/back_button_style "' anstelle von 'android: theme =" @ style/back_button_style "' – Joshua

+0

'android: theme =" @ style/AppTheme "' –

Antwort

1

Berichtigen Knopfandroid:theme Abschnitt.

Nicht

android:theme="@style/back_button_style 

style="@style/back_button_style" 

Dann Clean-Rebuild-Run tun.

+0

Ich versuchte, wie dies auch, aber es gilt teilweise bedeutet nur Textfarbe und Ränder werden angewendet, aber Hintergrund und Höhe werden nicht angewandt, ich prüfte separat, indem ich Hintergrund auf Knopf anwandte es funktioniert –

+0

@ ArchanaSM 'android: Hintergrund –

+0

@ArchanaSM entfernen' android: layout_height = "wrap_content" 'https://Stackoverflow.com/a/6608323/3395198 –

Verwandte Themen