Hide button text in android?

Please tell me how to hide the text on the button in android.

When I try to use this code, the button is hidden, but I just want to hide the text on the button.

Button b= (Button)findViewById(R.id.follow); b.setVisibility(View.GONE); 

Please tell me how to solve this.

Thanks.

+7
java android
source share
7 answers

I have a suggestion if you want to set the Text to a button but don't want to show it.

Just set the text in xml

 android:text="TEXT" 

then make font 0

 android:textSize="0sp" 

the text exists, but it is not visible.

+13
source share

If you just want to hide the text and not the b.setVisibility(View.GONE) button b.setVisibility(View.GONE) , this will not work.

It will hide the button itself, and also the button will not occupy any place in your layout, since you are using View.GONE.

Using b.setText("") should help you set only the empty text on the button.

You may need to call invalidate() to update the interface.

+2
source share

First back up the existing text on your button, then clear the button text to hide the text. And to show the text again, reuse the backup text:

 Button b = (Button)findViewById(R.id.follow); //Backup button text String mButtonText = b.getText(); //Now hide text b.setText(""); //To show text again b.setText(mButtonText); 
+1
source share

You can set the button text to just empty, rather than trying to hide the button.

 Button button = (Button)findViewByID(R.id.ButtonID); button.setText(" "); 

This will allow you to change the button text in your source so that you can change the button text when an event occurs, or even just set the button text blank when it is created.

+1
source share

on your xml. remove android:txt=" " on your button.

0
source share
 Button.setTextColor(getResources().getColor(android.R.color.transparent)); 

This will make the text transparent / hidden. It will save the original button size and save the source text.

0
source share

Try this <Button android:text="TEXT" android:textColor="#00000000"/>

general information:

 #<alpha><red><green><blue> 

all in hex 00 to ff

0
source share

All Articles