Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not removing the padding around button text

I have written a code to change the minWidth of a button so that I can get rid of the padding around the button text.

for(int i=0;i<26;i++){
    Button alphabet = new Button(getContext());
    alphabet.setText(""+(char)('A'+i));
    alphabet.setMinWidth(0);
    allAlphabets.addView(alphabet);
}

I am having a letter in each button and finally adding it to a layout dynamically. Due to padding, it is taking up much space, because of which I have set the minimum width to 0, but still it doesn't work. It shows the same default button. Please help.

like image 879
Santanu Avatar asked Jan 05 '17 06:01

Santanu


3 Answers

as you want a clickable view look like button with text

you can make a xml layout with your button or a cardview and textview inside it

then add it like this:

Button alphabetButton = LayoutInflater.from(context).inflate(R.layout.alphabet_layout);

so it's better than code design it's now a layout so you can modify the layout as you want

also you can add to your button in alphabet_layout.xml

android:background="@null"
like image 167
amorenew Avatar answered Oct 04 '22 05:10

amorenew


You have to apply LayoutParams with your Button alphabet.

like image 20
Naitik Avatar answered Oct 04 '22 06:10

Naitik


pls try set padding of button like

Button alphabet = new Button(getContext());
                alphabet.setText(""+(char)('A'+i));
                 alphabet.setPadding(0,0,0,0);
                allAlphabets.addView(alphabet);
like image 42
Manish Avatar answered Oct 04 '22 05:10

Manish