Android drawable selector and shape examples

Android drawable selector and shape examples - Hello friend inabnomaniiyaha, In the article that you read this time with the title Android drawable selector and shape examples, we have prepared this article well for you to read and take information in it. hopefully the contents of the post Artikel android-example,what we write you can understand. Alright, happy reading.

Judul : Android drawable selector and shape examples
link : Android drawable selector and shape examples

Baca juga


Android drawable selector and shape examples

Android drawable selector and shape examples

button view in a layout for an activity, activity_main.xml

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:gravity="center">

    <Button

        android:id="@+id/btn_open"

        android:layout_width="200dp"

        android:layout_height="40dp"

        android:background="@drawable/btn_open_selector"

        android:textColor="@drawable/btn_open_color_selector"

        android:text="Open"/>

</RelativeLayout>

drawable/btn_open.xml for the button style

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

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

    <stroke

        android:width="1dp"

        android:color="#2ebadc" />

    <corners android:radius= "50dp" />

</shape>

drawable/btn_open_pressed.xm

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

<shape xmlns:android="http://schemas.android.com/apk/res/android"

    android:shape="rectangle">

    <corners android:radius="50dp" />

    <stroke android:width="5px" android:color="#2ebadc" />

    <solid android:color="#2ebadc"/>

</shape>

drawable/btn_open_selector.xml

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

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- When selected -->

    <item android:state_pressed="true" android:drawable="@drawable/btn_open_pressed"/>

    <item android:state_activated="true" android:drawable="@drawable/btn_open_pressed"/>

    <item android:state_selected="true" android:drawable="@drawable/btn_open_pressed"/>

    <item android:state_focused="true" android:drawable="@drawable/btn_open_pressed"/>

 

    <!-- When not selected -->

    <item android:drawable="@drawable/btn_open"/>

</selector>

drawable/btn_open_color_selector.xml

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

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true" android:color="#ffffff" />

    <item android:state_activated="true" android:color="#ffffff" />

    <item android:state_selected="true" android:color="#ffffff" />

    <item android:state_focused="true" android:color="#ffffff" />

 

    <item android:color="#2ebadc" />

</selector>

Android drawable selector and shape examples



That's the articleAndroid drawable selector and shape examples

That's it for the article Android drawable selector and shape examples this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the articleAndroid drawable selector and shape examples with link addresshttps://inabnonapudyawanabing.blogspot.com/2020/11/android-drawable-selector-and-shape.html

0 Response to "Android drawable selector and shape examples"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...