Prabhjot Singh Chadha
Prabhjot Singh Chadha

Reputation: 53

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.

Upvotes: 5

Views: 41359

Answers (3)

Saeed Darvish
Saeed Darvish

Reputation: 631

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)
                
            }
        });

Upvotes: 5

Bwalya
Bwalya

Reputation: 1

public class TourActivity extends AppCompatActivity {
    private ImageView tour;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tour);

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

    private void launchThird() {

        Intent intent = new Intent(this, FirstActivity.class);
        startActivity(intent);
    }
}

Upvotes: -1

chace
chace

Reputation: 1

The top one I think it can implement by ImageButton simplely.

Another one need a Layout with a circle background, and contain ImageView and TextView.

Hope it will be help for you.

Upvotes: 0

Related Questions