Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the option to add a new preference screen in Android Studio 0.4.0?

Tags:

android

Android Studio 0.4.0

Hello,

I want to add a new Preference Screen in Android Studio. However, I cannot find the menu option to do it.

In Eclipse you would right click the resource directory | New xml file | resource type (preferences)

However, when I try and do this in Android Studio, there is no resource type preferences.

Do I have to do this manually now?

Many thanks for any suggestions,

like image 602
ant2009 Avatar asked Dec 21 '13 15:12

ant2009


People also ask

Where is the preference option in Android Studio?

The preference option doesn't exist anymore. You will need to right click the res -> new -> Android resource file and choose the resource type as xml in the dropdown. Then you will manually need to add the layout for preference xml.

What are preferences in Android Studio?

A node in a hierarchical collection of preference data. This class allows applications to store and retrieve user and system preference and configuration data.

What is Preferences screen?

Use the AndroidX Preference Library for consistent behavior across all devices. For more information on using the AndroidX Preference Library see Settings. Represents a top-level Preference that is the root of a Preference hierarchy. A PreferenceActivity points to an instance of this class to show the preferences.


2 Answers

The preference option doesn't exist anymore. You will need to right click the res->new->Android resource file and choose the resource type as xml in the dropdown. Then you will manually need to add the layout for preference xml.

like image 57
user2511882 Avatar answered Sep 30 '22 05:09

user2511882


In Android Studio 1.1.0: If you create a SettingsActivity it automatically sets up some xml preference resource files for you.

  1. Under src > main > java, right click a package (e.g. com.company.appname)
  2. New > Activity > Settings Activity
  3. Click Finish to accept the defaults
  4. Notice the new files:
    • SettingsActivity
    • values/strings_activity_settings.xml
    • xml (Directory)
      • pref_data_sync.xml
      • pref_general.xml
      • pref_headers.xml
      • pref_notification.xml

Note: The Activity uses some deprecated code. It might be best to look at the latest documentation for creating a preferences activity: http://developer.android.com/reference/android/preference/PreferenceFragment.html and for creating the XML resource file: http://developer.android.com/reference/android/preference/Preference.html

like image 32
Randy Avatar answered Sep 30 '22 06:09

Randy