Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an android raised button?

Ii have been searching in web for a week or so to get an example or tutorial on how to make a coloured raised button but no luck.

I want the following to be implemented in my app for better User interface experience.

And i did come across with the card view but when you write a big program with lots of buttons in it, the xml code will get bigger just because of this card view.

So if there is any quick and simple solution to the following please let me know.

Thank you

enter image description here

updated

            Normal button 

enter image description here

and with color 

enter image description here

like image 662
silverFoxA Avatar asked Mar 28 '15 08:03

silverFoxA


People also ask

What is raised button in Android Studio?

RaisedButton is the material design button based on a Material widget that elevates when pressed upon in flutter. It is one of the most widely used buttons in the flutter library. Let's understand this button with the help of an example.

What is raised button?

A raised button is based on a Material widget whose Material. elevation increases when the button is pressed. Use raised buttons to add dimension to otherwise mostly flat layouts, e.g. in long busy lists of content, or in wide spaces. Avoid using raised buttons on already-raised content such as dialogs or cards.


2 Answers

I think you actually want elevation in button. Don't use card as it require more resources. for lollipop devices use

<Button
    ...
    android:stateListAnimator="@anim/my_animator" />

and in anim folder in resources create my_animator.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:state_enabled="true">
        <set>
            <objectAnimator android:propertyName="translationZ"
                            android:duration="@integer/button_pressed_animation_duration"
                            android:valueTo="@dimen/button_pressed_z_material"
                            android:valueType="floatType"/>
            <objectAnimator android:propertyName="elevation"
                            android:duration="0"
                            android:valueTo="@dimen/button_elevation_material"
                            android:valueType="floatType"/>
        </set>
    </item>
    <!-- base state -->
    <item android:state_enabled="true">
        <set>
            <objectAnimator android:propertyName="translationZ"
                            android:duration="@integer/button_pressed_animation_duration"
                            android:valueTo="0"
                            android:startDelay="@integer/button_pressed_animation_delay"
                            android:valueType="floatType"/>
            <objectAnimator android:propertyName="elevation"
                            android:duration="0"
                            android:valueTo="@dimen/button_elevation_material"
                            android:valueType="floatType" />
        </set>
    </item>
    ...
</selector>
like image 140
Ajeet Avatar answered Nov 03 '22 07:11

Ajeet


You can try this alternative: Create a xml in your drawable folder: cardlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <gradient android:angle="90"
                android:endColor="@color/background_gray" android:startColor="#ccc" />
            <corners android:radius="4dp" />
        </shape>
    </item>

    <item
        android:left="0dp"
        android:right="1.5dp"
        android:top="0dp"
        android:bottom="1.5dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white"/>
            <corners android:radius="4dp" />
        </shape>
    </item>
</layer-list>

Now any view (Button, ListRow or imageView) you want to elevate. Just set the background of that view using this cardlayout.

android:background="@drawable/cardlayout"

NB change the cardlayouts background color according to your need.

like image 39
Mohammad Arman Avatar answered Nov 03 '22 07:11

Mohammad Arman