I have one activity that show my logo and i want change to second activity after that two seconds automatically.
I have done this but it doesn´t apply the effect.
Logo.java
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.logo_layout);
new Handler().postDelayed(new Runnable()
{
#Override
public void run()
{
Intent i = new Intent(Logo.this, Loggin.class);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(Logo.this);
startActivity(i, options.toBundle());
finishAfterTransition();
}
}, TIME);
}
res/transition/my_trasition.xml
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<fade
android:duration="1000">
</fade>
</transitionSet>
res/values/styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppFullScreen" parent="#style/Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowEnterTransition">#transition/transicion</item>
<item name="android:windowExitTransition">#transition/transicion</item>
<item name="android:windowAllowEnterTransitionOverlap">false</item>
<item name="android:windowAllowReturnTransitionOverlap">false</item>
</style>
Related
I wrote a code for setting a theme for activities setTheme(R.style.darkTheme); but i don't know how to write in fragments activity to set the theme.The code is for activities
if(sharedPref.loadNightModeState()==true)
{
setTheme(R.style.darkTheme);
}
else {
setTheme(R.style.AppTheme);
}
This is my style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="backgroundcolor">#color/background</item>
<item name="textcolor">#color/textcolor</item>
<item name="buttoncolor">#color/red</item>
</style>
<style name="darkTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#212121</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="backgroundcolor">#303030</item>
<item name="textcolor">#color/white</item>
<item name="buttoncolor">#color/red</item>
</style>
</resources>
This is my fragment code
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_state, container, false);
sharedPref=new SharedPref(getActivity());
if(sharedPref.loadNightModeState()==true)
{
setTheme(R.style.darkTheme);
}
else {
setTheme(R.style.AppTheme);
}
return view;
}
error is coming in this setTheme(R.style.AppTheme) line .
My app is in sticky immersive mode that the system navigation bar (I call it SNB) is hidden in running time of my app. It works well but exists one problem, it is each time I show a DialogFragment, the SNB will be appear. How can I hide it.
I have written a few line of code in my acivity class to make my app become fullscreen and sticky immersive mode.
MyActivity.java
#Override
protected void onResume() {
super.onResume();
hideSystemUI();
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
hideSystemUI();
}
public void hideSystemUI() {
// Enables regular immersive sticky mode.
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
);
}
MyDialog.java
public class MyDialog extends DialogFragment{
#NonNull
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
AlertDialog alertD = builder.create();
alertD.setView(view);
return alertD;
}
public void show() {
Activity activity = getActivity();
show(activity.getSupportFragmentManager(), "dialog");
}
#Override
public void onResume() {
super.onResume();
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
getDialog().getWindow().setAttributes((WindowManager.LayoutParams) params);
}
}
I followed the answer to show dialog without show SNB: https://stackoverflow.com/a/33589793/10467639 but it does not work as desired
MyDialog dialog = new MyDialog();
// Set the dialog to not focusable.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
dialog.show();
// Set the dialog to focusable again.
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
style.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/themeColor</item>
<item name="colorPrimaryDark">#color/themeColor</item>
<item name="colorAccent">#color/themeColor</item>
<item name="colorControlNormal">#color/black</item>
<item name="colorControlActivated">#color/black</item>
<item name="colorControlHighlight">#color/white</item>
</style>
<style name="BoldGrayHeaderTextView">
<item name="android:textSize">12dp</item>
<item name="android:fontFamily">#font/nunitosans_bold</item>
<item name="android:textColor">#color/darkColor</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<!-- Splash Screen theme. -->
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_background</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<!-- For CarPinItem on Map -->
<style name="carPinItemUnSelected">
<item name="android:textSize">12dp</item>
<item name="android:fontFamily">#font/nunitosans_regular</item>
<item name="android:textColor">#color/generalTextColor</item>
</style>
<style name="carPinItemSelected">
<item name="android:textSize">12dp</item>
<item name="android:fontFamily">#font/nunitosans_regular</item>
<item name="android:textColor">#color/white</item>
</style>
<!-- Style for drawer navigation item -->
<style name="NavigationDrawerStyle">
<item name="android:textSize">15dp</item><!-- text size in menu-->
<item name="android:listPreferredItemHeightSmall">40dp</item><!-- item size in menu-->
<item name="listPreferredItemHeightSmall">40dp</item><!-- item size in menu-->
</style>
<!--Style for textInputEditText -->
<style name="TextInputLayoutStyle">
<item name="android:fontFamily">#font/nunitosans_regular</item>
<item name="android:textSize">13dp</item>
<item name="android:textColor">#color/white</item>
</style>
<!--Style for profile bottom menu -->
<style name="BottomTextLayoutStyle">
<item name="android:fontFamily">#font/nunitosans_regular</item>
<item name="android:textColor">#color/black</item>
</style>
<style name="MyDatePickerStyle" parent="#android:style/Widget.Material.Light.DatePicker">
<item name="android:textColorPrimaryInverse">#color/black</item>
<item name="android:colorControlActivated">#color/successColor</item>
</style>
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/white</item>
<item name="colorControlHighlight">#color/white</item>
</style>
<!--BottomNavivagionView textsize-->
<style name="Widget.BottomNavigationView"
parent="Widget.Design.BottomNavigationView">
<item name="android:fontFamily">#font/nunitosans_regular</item>
</style>
<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowNoTitle">true</item>
</style>
</resources>
How can I solve this problem? Thank in advanced!
Followed this answer https://stackoverflow.com/a/23207365/8531215 ,I have tested and it works fine! modify onCreateDialog() method a little bit
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
AlertDialog alertD = builder.create();
alertD.setView(view);
Dialog dialog = alertD.create();
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
//Show the dialog!
dialog.show();
//Set the dialog to immersive sticky mode
dialog.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
//Clear the not focusable flag from the window
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
return alertD;
}
According to the docs here:
Implement onWindowFocusChanged(). If you gain window focus, you may want to re-hide the system bars. If you lose window focus, for example due to a dialog or pop up menu showing above your app, you'll probably want to cancel any pending "hide" operations you previously scheduled with Handler.postDelayed() or something similar.
So What I suggest you do is, change your code in MyActivity.java from:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
hideSystemUI();
}
to:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
if (!hasFocus){
//we lost focus due to DialogFragment
hideSystemUI();
}
}
I'm using PreferenceFragmentCompat for preferences and when I change theme preference using ListPreference to a dark theme and recreate activity text stays dark and becomes not visible. If I reopen this fragment text becomes white, but it returns to black color on orientation change
Here is my styles:
<style name="AppThemeLight" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="preferenceTheme">#style/preferenceLight</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:textColorPrimary">#color/primaryText</item>
<item name="android:textColorSecondary">#color/secondaryText</item>
</style>
<style name="AppThemeDark" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="preferenceTheme">#style/preferenceDark</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:windowBackground">#color/primaryText</item>
<item name="android:textColorPrimary">#color/primaryTextDark</item>
<item name="android:textColorSecondary">#color/secondaryText</item>
</style>
<style name="preferenceLight" parent="PreferenceThemeOverlay.v14.Material">
<item name="android:textColor">#color/primaryText</item>
<item name="android:textColorPrimary">#color/primaryText</item>
<item name="android:textColorSecondary">#color/secondaryText</item>
</style>
<style name="preferenceDark" parent="PreferenceThemeOverlay.v14.Material">
<item name="android:textColor">#color/primaryTextDark</item>
<item name="android:textColorPrimary">#color/primaryTextDark</item>
<item name="android:textColorSecondary">#color/secondaryText</item>
</style>
and fragment
class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener{
private lateinit var advertisePreferences: AdvertisePreferences
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
advertisePreferences = AdvertisePreferences(context!!)
}
override fun onResume() {
super.onResume()
(activity as AppCompatActivity).supportActionBar?.title = getString(R.string.settings)
preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
}
override fun onPause() {
super.onPause()
preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.app_preferences, rootKey)
}
override fun onPreferenceTreeClick(preference: Preference): Boolean {
when(preference.key){
}
return super.onPreferenceTreeClick(preference)
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
when(key){
getString(R.string.theme_key) -> {
activity?.recreate()
}
}
}
}
It seems it was bug in library. It now fixed in androidx.preference:preference:1.1.0-alpha02
I have one setting screen for change app themes at runtime. I know how to create material design theme. I have create one in my style.xml file
Here is code of my style.xml:
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryBackground</item>
<item name="colorPrimaryDark">#color/primaryBackground</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorControlNormal">#color/primaryBackground</item>
<item name="android:colorControlActivated">#color/primaryBackground</item>
<item name="android:colorControlHighlight">#color/primaryBackground</item>
<item name="android:textColorPrimary">#color/primaryBackground</item>
<item name="android:textColorSecondary">#color/primaryBackground</item>
<item name="android:windowAnimationStyle">#style/WindowAnimationTransition</item>
<item name="android:textCursorDrawable">#drawable/cursor_indicator</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Now I want to change runtime app theme from green to purple or yellow. Anything can any one tell me how can I create a color picker from theme selection and how can I create multiple themes in my style.xml for change it to runtime.
Have you seen this demo?
MultipleThemeMaterialDesign
See this class:
public class Preferences {
private static final BoolToStringPref[] PREF_MIGRATION = new BoolToStringPref[]{
new BoolToStringPref(R.string.pref_dark_theme, false,
R.string.pref_theme, R.string.pref_theme_value_red),
};
public static void sync(PreferenceManager preferenceManager) {
Map<String, ?> map = preferenceManager.getSharedPreferences().getAll();
for (String key : map.keySet()) {
sync(preferenceManager, key);
}
}
public static void sync(PreferenceManager preferenceManager, String key) {
Preference pref = preferenceManager.findPreference(key);
if (pref instanceof ListPreference) {
ListPreference listPref = (ListPreference) pref;
pref.setSummary(listPref.getEntry());
}
}
/**
* Migrate from boolean preferences to string preferences. Should be called only once
* when application is relaunched.
* If boolean preference has been set before, and value is not default, migrate to the new
* corresponding string value
* If boolean preference has been set before, but value is default, simply remove it
* #param context application context
* TODO remove once all users migrated
*/
public static void migrate(Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sp.edit();
for (BoolToStringPref pref : PREF_MIGRATION) {
if (pref.isChanged(context, sp)) {
editor.putString(context.getString(pref.newKey), context.getString(pref.newValue));
}
if (pref.hasOldValue(context, sp)) {
editor.remove(context.getString(pref.oldKey));
}
}
editor.apply();
}
public static void applyTheme(ContextThemeWrapper contextThemeWrapper) {
if (Preferences.darkThemeEnabled(contextThemeWrapper)) {
contextThemeWrapper.setTheme(R.style.AppTheme_Blue);
}
}
private static boolean darkThemeEnabled(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getString(context.getString(R.string.pref_theme),
context.getString(R.string.pref_theme_value_red))
.equals(context.getString(R.string.pref_theme_value_blue));
}
private static class BoolToStringPref {
private final int oldKey;
private final boolean oldDefault;
private final int newKey;
private final int newValue;
private BoolToStringPref(#StringRes int oldKey, boolean oldDefault,
#StringRes int newKey, #StringRes int newValue) {
this.oldKey = oldKey;
this.oldDefault = oldDefault;
this.newKey = newKey;
this.newValue = newValue;
}
private boolean isChanged(Context context, SharedPreferences sp) {
return hasOldValue(context, sp) &&
sp.getBoolean(context.getString(oldKey), oldDefault) != oldDefault;
}
private boolean hasOldValue(Context context, SharedPreferences sp) {
return sp.contains(context.getString(oldKey));
}
}
}
Checkout that demo, It will helps you to understand more.
Dynamic themes using style.xml
Here is my code
Style.xml
<resources>
<style name="AppTheme.Base.Green" parent="AppTheme.Green">
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#color/activity_bg</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.Base.Green.Dark" parent="AppTheme.Green">
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#color/activity_bg_black</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.Base.Purple" parent="AppTheme.Purple">
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#color/activity_bg</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.Base.Purple.Dark" parent="AppTheme.Purple">
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#color/activity_bg_black</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<!-- Base application themes. -->
<style name="ThemeApp.Green" parent="AppTheme.Base.Green"/>
<style name="ThemeApp.Green.Dark" parent="AppTheme.Base.Green.Dark"/>
<style name="ThemeApp.Purple" parent="AppTheme.Base.Purple"/>
<style name="ThemeApp.Purple.Dark" parent="AppTheme.Base.Purple.Dark"/>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
</resources>
themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme.Green" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/primary_green</item>
<item name="colorPrimaryDark">#color/primary_dark_green</item>
<item name="colorAccent">#color/accent_green</item>
<item name="colorControlHighlight">#color/primary_green</item>
<item name="android:textColorPrimary">#color/primary_text</item>
<item name="android:textColorSecondary">#color/secondary_text</item>
</style>
<style name="AppTheme.Purple" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/primary_purple</item>
<item name="colorPrimaryDark">#color/primary_dark_purple</item>
<item name="colorAccent">#color/accent_purple</item>
<item name="colorControlHighlight">#color/primary_purple</item>
<item name="android:textColorPrimary">#color/primary_text</item>
<item name="android:textColorSecondary">#color/secondary_text</item>
</style>
</resources>
v21/style.xml
<resources>
<style name="AppTheme.Base.Green" parent="AppTheme.Green">
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#color/activity_bg</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:navigationBarColor">#color/primary_green</item>
</style>
<style name="AppTheme.Base.Green.Dark" parent="AppTheme.Green">
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#color/activity_bg_black</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:navigationBarColor">#color/primary_green</item>
</style>
<style name="AppTheme.Base.Purple" parent="AppTheme.Purple">
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#color/activity_bg</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:navigationBarColor">#color/primary_purple</item>
</style>
<style name="AppTheme.Base.Purple.Dark" parent="AppTheme.Purple">
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#color/activity_bg_black</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:navigationBarColor">#color/primary_purple</item>
</style>
<!-- Base application themes. -->
<style name="ThemeApp.Green" parent="AppTheme.Base.Green"/>
<style name="ThemeApp.Green.Dark" parent="AppTheme.Base.Green.Dark"/>
<style name="ThemeApp.Purple" parent="AppTheme.Base.Purple"/>
<style name="ThemeApp.Purple.Dark" parent="AppTheme.Base.Purple.Dark"/>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
<!-- <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />-->
</resources>
method for change Theme runtime
private void setAppTheme() {
if (!MainController.preferenceGetString(Theme_Current, "").equals("")) {
if (MainController.preferenceGetString(Theme_Current, "").equals("Green")) {
setTheme(R.style.ThemeApp_Green);
} else if (MainController.preferenceGetString(Theme_Current, "").equals("Green_Dark")) {
setTheme(R.style.ThemeApp_Green_Dark);
} else if (MainController.preferenceGetString(Theme_Current, "").equals("Purple_Dark")) {
setTheme(R.style.ThemeApp_Purple_Dark);
} else if (MainController.preferenceGetString(Theme_Current, "").equals("Purple")) {
setTheme(R.style.ThemeApp_Purple);
}
} else {
setTheme(R.style.ThemeApp_Green);
}
}
after execute this method restart your activity needed
full source code
https://github.com/rkoshti/DynamicMaterialTheme
Here is the:
preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory
android:key="#string/pref_basicsettings_key"
android:title="#string/pref_basicsettings_title" >
<CheckBoxPreference
android:defaultValue="#string/pref_test1_default"
android:key="#string/pref_test1_key"
android:summary="#string/pref_test1_dlg"
android:title="#string/pref_test1_title" />
<CheckBoxPreference
android:defaultValue="#string/pref_test2_default"
android:key="#string/pref_test2_key"
android:summary="#string/pref_test2_dlg"
android:title="#string/pref_test2_title" />
</PreferenceCategory>
</PreferenceScreen>
BasicSettingsActivity.java
public class BasicSettingsActivity extends PreferenceActivity {
public static final String TAG = BasicSettingsActivity.class
.getSimpleName();
/** Called when the activity is first created. */
#SuppressWarnings("deprecation")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefs.registerOnSharedPreferenceChangeListener(mSharedPreferenceListener);
// add preference resource
addPreferencesFromResource(com.testapp.R.xml.basic_settings);
}
}
How do I change the text color in PreferenceCategory?
I added a new style:
<style name="PreferenceScreen" parent="Theme.AppCompat">
<item name="android:textColor">#ffffff</item>
<item name="android:textColorPrimary">#ffffff</item>
<item name="colorPrimary">#ff0000</item>
<item name="colorPrimaryDark">#ff0000</item>
<item name="colorAccent">#ff0000</item>
<item name="android:background">#CCCCCC</item>
</style>
and included it in the activity:
<activity android:name="com.smartipcamera.owlcam.ui.BasicSettingsActivity"
android:theme="#style/PreferenceScreen" >
</activity>
add a new style
<style name="SettingStyle">
<item name="android:background">#FFFFFF</item>
<item name="android:textViewStyle">#style/PreferenceStyle</item>
</style>
<style name="PreferenceStyle" parent="android:Widget.TextView">
<item name="android:textColor">#000000</item>
</style>
and include it in the Preference activity.
public class SettingsActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setting);
setTheme(R.style.SettingStyle);
....
}