Preference grouping without title - android

In the Android Settings section of the Material Design Guidelines, it mentions that section titles are optional for preference groupings, and in the image, the last section shows a grouping without a title but with a divider between groupings.
However, I am not able to implement this properly. If I use a PreferenceCategory with no title set, there is a blank space where the title would be. I can't just throw in a View in a PreferenceScreen to a draw a divider, and the promising looking PreferenceGroup is abstract or otherwise not able to be used.
So, how can I achieve this?

You can get the divider using app:allowDividerAbove="true" or app:allowDividerBelow="true" as per your need. Using PreferenceCategory tag is not needed as these attributes can be set in any level of preference hierarchy.

Related

How to make Preference widget appear below title in Android?

I'm new to Android development and wonder if there is an easy way to have a Preference (androidx.preference.Preference) with the widget appearing below the title? I am aware that layoutResource can be set to a custom layout, but I actually only need to change the widget (so I can set widgetLayoutResource instead of layoutResource) and I want it to appear below the title. If I change the whole layout to a custom one, I have to make it look like the other Preference layouts manually, which seems like an overkill given that I only want to change the title position.

I need a Toolbar that can dynamically add icons, and have them at certain positions

I've run into a very peculiar problem with Toolbars. The way my team currently uses the Toolbar is via a wrapper class, let's call it WrapToolbar.
So WrapToolbar will internally setup a Toolbar, and exposes some common Toolbar functions. Things like setTitle, getTitle, etc are available.
This WrapToolbar also sets up a default icon. This way all usages of the WrapToolbar will have this icon available for the screens that need it.
The problem with this approach is that for screens that require additional icons, have to add them via a Menu XML and the onCreateOptionsMenu function.
When we do that, the default icon setup with WrapToolbar gets pushed to the left, and the new icons from the Menu XML get added at the end.
This has worked fine for us until recently when requirements changed, and now are asking for the default icon to be at the end all the time.
I'm currently wrestling with the idea of doing a custom wrapper around Toolbar that exposes the ability to add icons, get the title, set the title, etc. This way we can put the icons in any order, and have ultimate flexibility in how our Toolbar looks.
I'm looking for some guidance on what that might look like. I also want to get some feedback on whether my initial idea to solve for this is flawed in some way I haven't foreseen.
Menus have a built in ordering based on the android:menuCategory attribute - you can use android:menuCategory="secondary" to push a menu item (like your default icon) to the end of the list - all MenuItems without a menuCategory will appear to the left of it.

Possible to change the spacing around MaterialCheckBox?

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.

custom ActionBar shape android

I'm trying to create a custom actionBar with a different shape (not rectangular) as shown on the image below, does anyone knows point me on the right direction?
At this point, it is no longer an ActionBar. Something like that would be a custom View.
It is missing a number of key components of the ActionBar such as the application icon and back arrow, and is lacking all of an ActionBar's styling.
You can create a completely custom View class and use that, or make a reusable layout and include it wherever needed using an include tag.

android preference horizontal divider in custom preference?

I've created my own custom preference objects that extend Preference. I've only created them because there are no Preferences for these custom data types.
Everything is working, but my custom preferences don't have the same appearance because they are missing the horizontal divider that the system preference objects have. I've looked for the code that is creating the horizontal divider, but I can't find where it is done.
The built in divider isn't just a thin bar. There is a bit of a gradient to it. I'm thinking that this may be in a layout file, but I can't find the layouts for the system preferences.
Anybody got an idea how this is implemented?
Very old post, but to those who stumble upon this. Wasn't sure if the OP was asking how to change the divider or where the divider images come from. So I'll address both.
How
Preferences uses a ListView for populating all the individual preferences. That means you can change the divider by using the .setDivider() method from ListView. A PreferenceActivity will already have the getListView() method for you. However for PreferenceFragments just use the android.R.id.list ID to find it.
If you don't want to change the divider through code, you can always use a theme by overriding the listDivider attribute. Eg:
<item name="android:listDivider">#drawable/custom_divider</item>
Note, that will change the divider for EVERY ListView in your app.
Where
The listDivider drawable used depends on what Android theme is activated. You'll find all these images in the installed Android SDK at this location:
[Android SDK]/platforms/[API]/data/res/drawable-[DPI]/
Just do a search for `*divider_horizontal*`, and you'll turn up quite a few. They are nine-patched and not all of them are solid colors.

Categories

Resources