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)) {
        } else {

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"

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s