开发者

Load preferences.xml without extending PreferenceActivity

开发者 https://www.devze.com 2023-02-10 21:05 出处:网络
Can I load preferences.xml without extending PreferenceActivity? I need this because: I w开发者_开发技巧ant custom title bar

Can I load preferences.xml without extending PreferenceActivity? I need this because:

  1. I w开发者_开发技巧ant custom title bar
  2. I want all of my Activities to extend my AbstractActivity


I don't think that its very easy, and can't test it right now, but technically it should be possible...

You should use PreferenceManager that has a createPreferenceScreen(Context ctx) method that (obviously) returns a PreferenceScreen, which, according to docs:

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.

And this class in turn has a getView(View convertView, ViewGroup parent) method that returns a View, and according to docs:

Gets the View that will be shown in the PreferenceActivity.

So I suppose that setting this returned View in your activity should display the same as the PreferenceActivity...


You can re-implement PreferenceActivity in your own activity class. Here's the source code of PreferenceActivity class.

It's rather small, so I don't think it'll be difficult to understand it.

0

精彩评论

暂无评论...
验证码 换一张
取 消