ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [5] Image Button Effect (drawable)
    Develpment/Android Using Sample 2020. 9. 13. 21:35

    1. Image Button Effect


     drawble

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
     
        <item
            android:state_pressed="false"
            android:drawable="@mipmap/ic_launcher"/>
     
        <item
            android:state_pressed="true"
            android:drawable="@mipmap/ic_launcher_2"/>
    </selector>
    cs

    * 이미지를 버튼의 백그라운드로 넣을 경우 누른 효과가 나지 않음.

    * res/drawable 에 추가하여 정의.

    * state_pressed 가 false일 경우 누르지 않은 상태의 이미지.

    state_pressed 가 true일 경우 눌렀을때의 이미지를 넣음.


     Layout

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.sin.custombutton.MainActivity"
        android:orientation="vertical">
     
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/button"/>
    </LinearLayout>
     
    cs

    * background 값을 @drawable/button 으로 위에서 정의한 xml 파일명을 넣음.


    2. 결과화면


     


    * 누르기 전의 버튼과 눌렀을때 변한 버튼의 모습

    'Develpment > Android Using Sample' 카테고리의 다른 글

    [7] Alert Dialog  (0) 2020.09.13
    [6] Menu  (0) 2020.09.13
    [4] Custom Button  (0) 2020.09.13
    [3] ListView  (0) 2020.09.13
    [2] Inflater  (0) 2020.09.13

    댓글

Designed by Tistory.