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...
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'm creating two different themes black and white. In one of the themes, Its completely black background. But in other theme, I am going to use two different background colors for two different screens (layouts).
For example, first screen red color and second, and third are white colors.
I'm stuck there. Please help me to do it.
Thanks in advance.
Define several themes with android:windowBackground set to the different colors and then call setTheme() in your activity's onCreate(). These themes can inherit from your main app theme.
There should be different XML files for different pages/screens. These can be found in res -> layout. After opening the XML file you want, click on the "Graphical Layout" tab. Then click on the page. Then you will see a list of settings/properties for the layout, the bottom left of the screen. From here you can change whatever you want :)
I tried to run my activity in full screen mode using this method:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen
But after it my all design were changed. My Edittext-s which had only a line below now become rectangles and buttons design are changed too.
How to avoid this situation?
Try this theme instead:
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen"
The theme you are applying to your Activity is old and I think even deprecated. The Holo themes are the ones you are looking for.
I have a ListView which should have the "Theme" theme in portrait and the "Theme.Light" theme in landscape mode. How do I do that? The theme seems to be tied to the activity, and for the ListView I can only change the style, but I dont find a style which works.
Or, is there a way to change the activity's theme based on orientation? By code or prefereable by xml?
To be more precise and explain the reason: I try to start experimenting with the fragment compatibility library. The starting activity shows in portrait mode a list which looks best with black background. When I touch a list item, a second Activity starts and shows a ListView which better looks on white, so this second Activity has the Theme.Light. Works so far.
When I switch to landscape, I try to show both ListViews aside. The second one on the right has to have a white background. The first one on the left could stay on white also (so the whole activity could change the theme), but I'd like to see one on black and one on white, if possible. (I put both ListViews in Fragments, this is done and works. Only the colors are wrong.)
Any ideas?
Greetings, Joerg
You would create a layout.xml file for each orientation, and put each in the proper folder according to the Android standards.
Then, you can set the different style as an attribute in each XML file.
Android will use the appropriate layout file automatically, depending on orientation.
I need to eliminate the gap between buttons in a layout. I'm doing it by setting background color for a style and applying that style to my buttons. This eliminates the highlighting upon press, which I of course need. Here is a solution to this problem, but it requires extra actions to be taken with Java code. Can I make it statically, only with XMLs?
Also, if there is any other way to remove the gap without changing the other aspects of button's appearance - please suggest. The only requirement is it should be done with XML (however, if no other options exist, I can inherit Button class).
You can use StateList xml for background of your button