Reputation: 273
I have a button style, but background
, colorAccent
and colorButtonNormal
not working on my button. I tried to change background drawable, and change different colors, and change style=
to android:theme=
but in wont help. Here's my style:
<style name="ButtonWithBorder" parent="Widget.AppCompat.Button.Colored">
<item name="colorAccent">@color/colorPrimary</item>
<item name="colorButtonNormal">@color/colorPrimary</item>
<item name="android:textColor">@color/colorAccent</item>
<item name="android:textAllCaps">true</item>
<item name="background">@drawable/btn_border</item>
<item name="android:textSize">@dimen/button_text_size</item>
</style>
My button:
<Button
android:id="@+id/descriptionReserveButton"
style="@style/ButtonWithBorder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:text="@string/reserve_place"
/>
<Button
and my background:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_outline" android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimary"/>
</shape>
</item>
<item android:drawable="@drawable/btn_outline" android:state_focused="true">
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimary"/>
</shape>
</item>
<item android:drawable="@drawable/btn_outline"/>
I want to style my button once, and rest of time just use this style.How can i accept my style to button
what i need:
EDIT
my mistake was in
<item name="background">@drawable/btn_border</item>
it have to be <item name="android:background">@drawable/btn_border</item>
new screen
Upvotes: 1
Views: 4054
Reputation: 9692
Try this
<Button
android:id="@+id/descriptionReserveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
style="@style/MyButton"
android:text="reserve_place" />
Style
<style name="MyButton" parent="android:Widget.Material.Button" tools:targetApi="lollipop">
<item name="android:textColor">#149aed</item>
<item name="colorButtonNormal">#020e39</item>
<item name="android:textAllCaps">true</item>
<item name="android:background">@drawable/edterr</item>
</style>
@drawable/edterr
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#030a64" />
<stroke
android:width="1dp"
android:color="#149aed" android:dashWidth="5sp">
</stroke>
<corners android:radius="5dp" />
</shape>
Upvotes: 3
Reputation: 1715
In you styles.xml create a style for your button with the background:
<style name="ButtonStyle" parent="Widget.AppCompat.Button">
<item name="android:background">@drawable/shape_round_rect</item>
</style>
The drawable shape_round_rect.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<stroke android:color="#2c73ca" />
<corners android:radius="4dp" />
<solid android:color="@color/colorPrimary" />
<padding android:bottom="4dp" android:left="6dp" android:right="6dp" android:top="4dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<stroke android:color="#2c73ca" />
<corners android:radius="4dp" />
<solid android:color="@color/colorPrimary" />
<padding android:bottom="4dp" android:left="6dp" android:right="6dp" android:top="4dp" />
</shape>
</item>
</selector>
And set the style in your button:
<Button
android:id="@+id/descriptionReserveButton"
style="@style/ButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:layout_margin="12dp"
android:text="Reserve Place" />
Upvotes: 1