save settings in android app

1. settings

use getSharedPreferences(prefFileNameString, mode).

        sharedPreferences = getSharedPreferences(getString(R.string.app_pref), MODE_PRIVATE);
        if (sharedPreferences.getBoolean(getString(R.string.night_mode_pref_key), true)) {
            setTheme(android.R.style.Theme_Holo);
        } else {
            setTheme(android.R.style.Theme_Holo_Light);
        }

I just need 1 settings file in my current app, so I only need to define a string in resource for the “prefFileNameString” and use it across all activities.

2. change theme

The above code is used for switch between holo and holo light theme. Make sure they are before your setContentView method.

3.add hr

About adding a hr in the view, we can use the following setting:

<!--add a separate line in between-->
    <View android:layout_width="fill_parent"
          android:layout_height="1dp"
          android:background="@android:color/darker_gray"/>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s