Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coloring Buttons in Android with AppCompat

Does anyone know how to change the button color?

but one particular button, not all the buttons of the application using the XML.

The android:backgroundTint attribute doesn't work on pre-Lollipop even with AppCompat library. Only colorButtonNormal from theme works on pre-Lollipop.

Is that true? what a shame

I'm using this drawable (is a simple green color) with a button, but when I use the button turns out to be higher than the normal button.

this is the file btn_green.xml

<?xml version="1.0" encoding="utf-8"?>

<item android:state_pressed="true"><shape>
        <solid android:color="#ff5722" />

        <corners android:radius="4dp" />
    </shape></item>
<item android:state_focused="true"><shape android:shape="rectangle">
        <solid android:color="#4caf50" />

        <corners android:radius="4dip" />

        <stroke android:width="1dip" android:color="#F0FC00" />
    </shape></item>
<item><shape>
        <solid android:color="#4caf50" />

        <corners android:radius="4dp" />
    </shape></item>

the button is this:

            <android.support.v7.widget.AppCompatButton
            android:id="@+id/btnIngresar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_green"
            android:text="Hello"
            android:textStyle="bold" />

when i use the drawable, the button is higher than the normal button (without the drawable), i don't know why.

like image 565
seba123neo Avatar asked Jun 05 '15 13:06

seba123neo


People also ask

How to change the style of Buttons in Android?

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

What is Appcompat button?

AppCompatButton widget enhanced with emoji capability by using EmojiTextViewHelper . A Button which supports compatible features on older versions of the platform, including: Allows dynamic tint of its background via the background tint methods in androidx.

How to style Buttons in Android studio?

To add a button, that has an Android style all you need to do is to drag and drop a button from the Palette to your layout. For most versions that would mean a grey button with all corners at 2dp roundness. Check our blog, if you need to learn more about using Android Studio Layout Editor.

What is default color of button in Android?

When I open a new android studio project, the default color for button is purple.


1 Answers

if you want below style

enter image description here

add this style your button

style="@style/Widget.AppCompat.Button.Borderless.Colored"

if you want this style

enter image description here

add below code

style="@style/Widget.AppCompat.Button.Colored"
like image 74
Jinu Avatar answered Oct 12 '22 22:10

Jinu