How to update ActionBar after change language in PreferenceFragment? - android

I want to update language in app by click on the preference in setting fragment which I use preference fragment. Successfully, I can update almost everything in app after change language except ActionBar in each activity including the setting fragment. The only solution I know is to restart app.
Again, I want to change app language include ActionBar after click change in setting. Is it possible?
I have search this question, but not solve yet. Here is my setting layout.
Please help. Thank

Finally, I found a solution:
App won't change Actionbar language after change locale. I won't refresh it. It will change when I remove app from the recent app which make the app completely close.
To solve:
I use setTitle(R.id.myapplabel) when you want to refresh app or
oncreate, so no need to restart app.
Translate activity label on string.xml and it works.

Related

How to change Android App theme at runtime like Google Inbox App?

The inbox app features a navigation drawer. Upon clicking on any navigation drawer item a fragment is loaded (most probably) and during this transaction the app theme changes. Changing app theme requires setTheme() method to be called before setContentView(..) in the onCreate() method of the activity. The super fluid UI indicate the use of fragments so how is this achieved without recreating parent activity (otherwise there would have been a lag for sure).
The snooze fragment hase oragne like theme
The inbox fragment has blue like them
You can actually change the theme's style, but only before calling setContentView(#ResId int) method. Something like this perhaps?
getTheme().applyStyle(isDashUser ? R.style.redStatusBar : R.style.blackStatusBar, true);
setContentView(R.layout.my_activity);
If you look closely when changing the page there's a slight graduation between the two colours. This probably suggests they have a system separate from theming to re-colour all the UI elements.
One my apps has a very similar colour change feature, and I just have methods set up to manually re-apply the relevant colours to each UI element. Of course Google probably have some super slick way of doing it that they'll never share with anyone.

preference activity UI for settings

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.

Change Theme while app is running

I am working on an app and I want to have a night mode option. I have already created two themes named HoloLight and HoloDark. I can set these themes in the apps manifest and they both work fine. The problem is I can't find a way to switch between the two with code. Is there a good way to do this?
you can use setTheme method in onCreate() Method like
setTheme(android.R.style.Theme_Black);
This should be above setContentView
You can change theme only before setcontentview.
setTheme(android.R.style.HoloDark); so basically to change theme in app you will have to restart your activity. see this example for that. If you have some data to be saved, save that in instance state by using these functions in activity, onSaveInstanceState(Bundle)
onRestoreInstanceState(Bundle)

Android using switchpreference to set color background

How can I change the color of the app I'm trying to develop.
I have used a switch statement under preferences menu, but do not know how I can code this, so that when the user clicks on the switch, the background color is changed across the whole app.
Does anyone have any idea of how this can be done?
Thanks
You can enable the user to change the theme using preferences. This will change the background color throughout the application in accordance with the choice. The following thread is talking about the same problem: How to change current Theme at runtime in Android. Hope this helps.

Dynamically Updating Launcher Icon in Android

I am trying to put a dynamic value in the launcher icon of android, as number of messages will be displayed in the message icon. As the icon is static and initialised before the application starts, Is there any way to achieve this??
For Android Launcher Icon you can't. It is impossible. (Or by Making your own launcher) The only one thing is you have to make a Android-Widget for this purpose. Which looks like a application icon. But it will act as a widget.
Also Make a dynamic launcher icon
simple answer is you can't do it also this question says the same. But there may be advance tricky methods/ways that I'm not aware of.
But you may try and develop widgets that changes dynamically.
You have to design your icon as a selector instead of drawable. Have a look at this.
You cant update because its related to manifest.xml stuff only possible with software upgrade.

Categories

Resources