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.
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"
You have to apply LayoutParams
with your Button alphabet
.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With