Search code examples
androidandroid-layoutandroid-intentandroid-activity

How to add icon image button in android studio


image
I want to design the layout of this type of app(as shown in the image). In this layout when we click the circle icon it moves to next page. I want to know how its done.


Solution

  • in drawer folder create circle_background.xml and put this code to it :

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
        <solid android:color="#FE4543"></solid>
         <stroke android:color="#FE4543" android:width="1dp"></stroke>
    
    </shape>
    

    so now in your activity add image view like this

    <ImageView
            android:layout_width="wrap_content"
            android:gravity="center"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_action_search"
            android:padding="15dp"
            android:id="@+id/btn_search"
            android:background="@drawable/circle_background"
            />
    

    and if you want to add click action on this you have to use intent something like this , my view id is btn_search so at the first i have to find it like this and then set onclick listener for it like below

     ImageView btnSearch= (ImageView) findViewById(R.id.btn_search);
            btnSearch.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent= new Intent(getApplicationContext(),ExampleActivity.class)
                    
                }
            });