1

Created custom style for button when apply the style for button it is partially. Here is the style code snippet.

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

After applying the style only the text color changes to white since i given the text color as white in style but other credentials are not applied background, before applying the button text color was black. So I not getting why it is partially applying the style.

I tried like this also but it is not working

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

I am not getting what and where is the bug in the code.

halfer
  • 19,824
  • 17
  • 99
  • 186
Archana S M
  • 31
  • 1
  • 10
  • Possible duplicate of [How to create custom button in Android using XML Styles](https://stackoverflow.com/questions/18507351/how-to-create-custom-button-in-android-using-xml-styles) – akhilesh0707 Sep 01 '17 at 09:03
  • try `style="@style/back_button_style"` instead of `android:theme="@style/back_button_style"` – Joshua Sep 01 '17 at 09:03
  • `android:theme="@style/AppTheme"` – IntelliJ Amiya Sep 01 '17 at 09:04
  • style="@style/back_button_style", yaa I tried like this also but it is applying partially means only text color and margins are applied, but background and height is not applying, I checked separately by applying background on button it works – Archana S M Sep 01 '17 at 09:14

1 Answers1

1

Rectify Button android:theme section .

Don't

 android:theme="@style/back_button_style

Do

style="@style/back_button_style"

Then Clean-Rebuild-Run .

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198