Android default Button class provides a really big button.
There is a lot of wasted space around. Now I want to create really small buttons, that are only slightly bigger than the text/caption. How to do this from code? So far I found the following method, but it is still providing too big buttons and wasting too much space:
A. Create an XML (smallbutton.xml) in the res/layout:
<?xml version="1.0" encoding="utf-8"?>
style="?android:attr/buttonStyleSmall"
android:text="color"
android:padding="0dp"
android:layout_margin="0dp"
android:textSize="8dp"
android:maxHeight="2dp"
android:maxWidth="2dp"
/>
B. From your code inflate this and add to the view:
Button pickBackColor = (Button) this.getLayoutInflater().inflate(R.layout.smalbutton,null);
...
LinearLayout linLayout = new LinearLayout(this);
linLayout.addView(pickBackColor);
Now the problem is that the button is still too big, it uses too much space around (on the left, right, above, under) of the text.
Any hint how to decrease the size of the button further?
try this in your code:
in .xml file... you need to pass small value to layout_height and layout_width in xml file...... try this.
Change value as per your requirement...
For your information there is also the default style provided by Android that defines smaller buttons:
You can also if necessary modify this default style and define custom attributes in your file styles.xml. Here is an example with the modifications described in the question:
Then you just need to call it in the XML:
Buttons have a minimal height and width (typically of 48dp respectively 64dp by default). So add
to get really small buttons: