문경욱
문경욱

Reputation: 51

android studio - How do I resize buttons based on text?

I'm making two buttons.

if One button is clicked, the other button's text is changed.

I coded initial status using setText

mBtn.setOnClickListener(this);
mBtn.setText("Connect");

and changing text using

mBtn.setText("Disconnect");

In this case, button's length is fixed initial length.

What can i do?

enter image description here

Upvotes: 0

Views: 217

Answers (2)

Gaurav
Gaurav

Reputation: 181

 <Button

                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Connect"
                    android:padding="5dp"
                    />

Upvotes: 0

sudesh regmi
sudesh regmi

Reputation: 546

use this on your layout it will work. remove fixed width first.

 android:layout_width="wrap_content"

Upvotes: 2

Related Questions