Is ist possible to reduce the text padding inside a normal Android Button a bit, in order to reduce the buttonĀ“s width?
Of course the whole text should be still visible.
There're android:minHeight and android:minWidth attribute already set on a button. Make them 0dp or 1dp to make the background fit to the text.
The "normal" Android button varies between themes, but you probably want to define a custom style for the button that inherits from your button of choice.
Related
I'm curious to know whether it's possible to change the default spacing that's placed around MaterialCheckBox... or whether there are plans to allow for this.
Let's say, for the sake of example, I have a CheckBox defined with four TextViews around it (to the left, right, top and bottom of it) and I specify no margins on any of the five Views. If I define my app's theme as Theme.AppCompat.Light then this CheckBox is rendered with equal spacing around it as follows:
If I change the app's theme to Theme.MaterialComponents.Light and make no other changes to the app then the CheckBox is rendered as follows:
Note the unequal spacing which I would like to customise on a per-need basis. There's nothing mentioned in the MaterialCheckBox documentation and I can't see anything obvious in the class definition about being able to change this spacing.
(For what it's worth I'm using the latest version of the com.google.android.material:material library, i.e. 1.1.0-alpha03. And everything I've said above holds regardless of whether I define a CheckBox, AppCompatCheckBox or MaterialCheckBox in my layout. The key thing is changing the theme from Theme.AppCompat.Light to Theme.MaterialComponents.Light.)
This looks related to MaterialCheckBox enforcing a 48dp minTouchTargetSize for accessibility using android:minWidth in the CheckBox style (this should be added to the documentation). Setting android:minWidth to 0dp should work.
I want to customize my textview as per my requirement. I have to add padding or margin dynamically when text is too long and it should look like my screenshot which I have attached here. Can anyone help me how can I implement it and below is my screenshot.
Try using this. It is customizable.
I used it so that I can have different color texts inside my "textview" , and also I used it, cause I did on it a code to resize the text size, so that it fits in the screen height. But if that was possible, I'm pretty sure what you want to do is also possible.
https://github.com/DavidPizarro/AutoLabelUI
I have two buttons in my layout. They appear fine with padding around their sides. However, when I change the activity's theme to #android:style/Theme.Black.NoTitleBar
All of a sudden, the buttons become really small with no padding around them. Why is this happen? All it takes is for me to remove the theme attribute (remove NoTtitleBar) and that fixes them. What does that have to do with the buttons?
Need to use
android:theme="#android:style/Theme.Holo.NoActionBar"
instead. The one I was using before is for gingerbread and so it changes the default style of buttons, etc...
I'm just starting to learn android and i had a doubt concerning to view padding. Referring to What controls the default padding between views? , Is the padding included in the size we specify to the view ? All help appreciated!
EDIT: Also does a layout add padding to itself by default ?
In the question you linked to, the padding is caused by the button's background being a nine-patch and having some transparent borders in it. Since the "padding" is part of the background resource, it is include in the image size and you don't need to do anything to make it show up.
However, if you are creating your own Views, or changing the background or foreground resources of the system provided Widgets, you may want to use the android:padding* attributes to specify the various paddings.
I am having quite a challenge with this. If the toggle button height is less than 30dp, the text disappears.
I am wondering is this a design issue or can anyone help me with a workaround?
You could try setting the padding to 0. Sometimes you need to override the default padding.
If that doesn't do the job you can use custom graphic instead of android default graphic. The default toggle button graphic for android is 9-patch and in this there is some build in padding you can't disable from code.
You could try to setIncludeFontPadding to false. This can be done both in code and xml.
As a last resort you have to change the textsize in order to fit inside the button.