After reading the settings part of the Material Design available here, I came across the following screenshot:
The 3 first preferences presented are seekbars but I cannot find anything about it, even in the support libraries.
Am I missing something here or Google just created a custom preference that is not available yet?
Developer docs explain how to achieve custom views in Settings.
TL;DR
You need to create your custom layout file having ImageView, TextView and SeekBar wrapped inside a LinearLayout.
Then you write a class which extends Preference implements SeekBar.OnSeekBarChangeListener and override all the necessary methods to listen to SeekBar changes.
In the Preference XML file add your custom class as a tag and you will see a similar UI.
SeekBarPreference is actually natively present in Android and is not a custom class that needs to be implemented.
You can see it in the Palette (highlighted).
Related
With Android x the DialogPreference is moved to DialogPreferenceCompat . As there are many ways to make a custom layout in the Preference settings .
I am looking for more clean and better way to make a custom layout that when clicked opens the Custom Number Picker Dialog Box. I would like to make a custom layout with a button .
The issue right now I am facing is there is no onCreateDialog override method in DialogPreference and I am not sure how to make the changes. It looks like due to DialogPreferenceCompat used in android x my most of the code is broken.
How can I make the correct code changes? There are many ways to write the Custom Preference layout but I don't know which one is good one.
I'm beginner in android , now I'm building an android application. .
I'm working in setting screen now and in my research i have seen so many applications that is using preference activity for the settings.So i started my setting page using preference activity. But in my case , my application settings have some options that don't need to save as preference. And that are also connecting with server and the EditTextPreference dialog will be also different. So i got confused in this case.
So what should i do? Do i have to change this to a LinearLayout?
Please help
The preference compat fragment and activity is there to make it simple to create an interface and save it to SharePreference. but you can't change much of the thing. I believe the sharepreference compat and component is itself has the listener when is changing. So let it save to preference even if you don't need it probably Ok. Also if your mockup or design for EditTextPreference is look different from native android then You can try use theme and style to change the look and feel of EditText just for preference only.
Also, You probably can use scrollview + constrainlayout or linearlayout to build it but you're make extra work such as save/load to/from preference, UI like sub preference ...etc. I would sugguest to go with Theme and Style but if your UI is completely different and can't be adapted with Preference then it left no choice. Constraint Layout would be better than LinearLayout.
The PreferenceFragment attached to a preference activity is the ideal way to have a settings screen. You will however need to implement the PreferenceChangeListener in the PreferenceFragment to listen for preference changes and save the changes. If you have options that do not need to be saved you can still add them to the xml and make them disabled by setting android:enabled = false.
EditTextPreferences can have their own UI feel by using the android:theme = #style/yourstyle and specifying the style you want in your styles.xml file
Goodluck.
I need to get all views that have text for setting custom fonts.
I can develop a recursive method in myBaseActiviy class for getting all views with checking instanceof when programme is in OnCreate(). But I worry about the performance? I interest your idea? What should I do?
There is no best way. An approach, the one I use, is to subclass TextView, adding a new attribute to specify the font I want to use, delegating the logic to the subclass self.
I think the easiest way is to create your own TextView. It's not as hard as it sounds ;-).
This is the origional answer:
https://stackoverflow.com/a/19679639/2767703
And this is the link you'll need:
http://javatechig.com/android/using-external-fonts-in-android-view
Or if you want to set the font in the xml:
https://stackoverflow.com/a/7197867/2767703
Warning
If you are developing for Android versions lower than Android 4.0 then
you should change the code. In these versions there is a bug that
doesn't free up memory for typefaces. What you should do is create a
HashMap that allows reusage of Typefaces. You can find more in the
comments of the last link (search for the comment with the highest
upvote).
You could also use this:
https://stackoverflow.com/a/16883281/2767703
This changes the font of every text in your application. Note: You still have to look at my warning if you use this.
You can do something like this:
Add new attribute for store font in style.
Extend your view to handle this attr and set font by view when do you need.
You can find example of using and creation of new attribute for font at this link https://stackoverflow.com/a/12282315/2156937
Hope it helps.
I took a look at the preference activity that Android use for settings. i'm looking for something like UISwitch as shown in below image, does Android have one like this.
I can see the nearest control on Android preference settings is "list preference"
There is ToggleButton and CompoundButton (one extends the other).
But those have a different default display widget then what you are looking for. However either could be used along with your own drawable resources to create the "switch" type control that you are after.
But by default no the system does not include a widget that serves this function and looks the way you want it to.
No, In Android its called ToggleButton.
But still it can be developed by extending RadioButton placed in RadioGroup and giving its UI way you wanted.
I want to create a component that will appear as a navigation menu for an Android application. Basically, the custom component is a rectangular "Div" (to use HTML terms) that contains six buttons. Each button provides a link to another part of the application. I want to use this on every "page", so I want to make it easy to maintain.
What is the recommended class to extend for creating custom components like this? (I've seen the "Widget" class, but not sure If this should only be used for widget that appear outside the app (like Google search))
And
Is the process as simple as creating the custom "Widget" class with it's own XML layout and then adding it to each Activity class?
The class to extend is View, the Widget class is for widgets in the homescreen. This is a nice doc to read: Building Custom Components, I suggest to look at the Compound Controls section, that seems suitable for your problem.
Is the process as simple as creating the custom "Widget" class with it's own XML layout and then adding it to each Activity class?
Yes, once you have written your own view, you just have to add it to your layouts in the XML (just like you do with the android views), something like this:
<com.your.package.YourNiceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>