AhMed ShOda
AhMed ShOda

Reputation: 1

Custom button designs using XML Android Studio

I tried a lot of things but could not able to achieve what i want? here are the button designs that I wanted to create using XML in Android so that I can easily support it for Multi Screen.

Design 1

enter image description here

Design 2

enter image description here

Upvotes: 0

Views: 400

Answers (1)

Sho_arg
Sho_arg

Reputation: 383

You cannot design a button like this but you can achieve your layout design by using imageview in your Android app like a button with the onClick event given

final ImageView v = (ImageView) findViewById(R.id.button0);
    v.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            switch (arg1.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                v.setImageBitmap(res.getDrawable(R.drawable.img_down));
                break;
            }
            case MotionEvent.ACTION_CANCEL:{
                v.setImageBitmap(res.getDrawable(R.drawable.img_up));
                break;
            }
            }
            return true;
        }
    });

And you define a selector as follow

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"   
    android:drawable="@drawable/img_down" />
<item android:state_selected="false"   
    android:drawable="@drawable/img_up" />
</selector>

Upvotes: 1

Related Questions