Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:background is not working in style.xml

Can anyone please suggest about below issue.

I tried to use custom button style having drawable(curve_button.xml) file.

Colors has applied and looking nice but it seems to be issue with <item name="android:background">@drawable/curve_button</item> as it didn't applied.

style.xml

 <style name="CustomButton" parent="Widget.AppCompat.Button.Borderless.Colored">
    <item name="colorButtonNormal">@color/book_appointment</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:background">@drawable/curve_button</item>
  </style> 

curve_button.xml

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
  <item>
    <shape android:shape="rectangle">
      <padding
         android:paddingLeft="34dp"
         android:paddingRight="34.4dp"
         android:paddingTop="16dp"
         android:paddingBottom="16dp"
        />
      <corners android:radius="8dip" />          
    </shape>
  </item>
</selector>

button layout

<Button
            android:id="@+id/idBookAppontment"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="Book Appointment"
            android:theme="@style/CustomButton"
            android:layout_marginBottom="12dp"
            android:layout_marginTop="6dp"
            android:layout_marginLeft="38dp"
            android:layout_marginRight="37dp"            
            android:inputType="textCapWords"
            android:layout_gravity="bottom"
            local:MvxBind="Typeface StringToFont('Effra_Rg')"
            android:layout_below="@id/providerTabbarHost"
            android:layout_alignParentBottom="true" />
like image 378
Chanki Avatar asked Feb 27 '18 11:02

Chanki


People also ask

How to change android Button style?

To change the default Button style of the application we can use the android:buttonStyle attribute in the AppTheme style inside the styles. xml.

Where is colors XML in Android Studio?

XML file saved at res/values/colors.

Where do I find Styles XML in Android Studio?

Styles and themes are declared in a style resource file in res/values/ , usually named styles. xml .


1 Answers

Use this

    <?xml version="1.0" encoding="utf-8" ?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
                <padding android:paddingBottom="16dp" android:paddingLeft="34dp" android:paddingRight="34.4dp" android:paddingTop="16dp" />
                <solid android:color="@color/colorAccent" />
                <corners android:radius="8dip" />
            </shape>
        </item>

</selector>

Instead of this

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
  <item>
    <shape android:shape="rectangle">
      <padding
         android:paddingLeft="34dp"
         android:paddingRight="34.4dp"
         android:paddingTop="16dp"
         android:paddingBottom="16dp"
        />
      <corners android:radius="8dip" />          
    </shape>
  </item>
</selector>
like image 113
AskNilesh Avatar answered Oct 21 '22 00:10

AskNilesh