更改 PreferenceActivity 文本颜色
我想将 Android 应用程序的首选项屏幕的外观更改为深色文本颜色。我该怎么做? (我已经将背景更改为白色)
I want to change the look of my Android app's preference screen to dark text color. How can I do this? (I´ve already changed the background to white color)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您使用扩展了
PreferenceActivity
的 Activity。您可以使用setTheme
方法在您的首选项屏幕上设置自定义主题。只需在
res/values/themes.xml
中定义一个即可。它看起来像这样:
然后将其设置在您的活动中:
I assume you use an Activity which extends the
PreferenceActivity
. You can use thesetTheme
method to set a custom theme on your preference screen.Just define one in
res/values/themes.xml
.It would look like this:
Afterwards set it in your Activity:
我接受了乌迪尼奇的想法,但我对其进行了一些改进。
现在可以随时设置(在本例中)PreferenceCategory 的颜色,而不仅仅是在膨胀视图时。
怎么做?
首先,创建您的自定义类,例如这个类:
完成后,您必须在 XML 中定义设置时使用它。
在您只需要在您的 java choiceActivity 中使用此循环之后:
这就是想法。您可以随时对任何设置执行此操作。
在使用此代码之前,布局必须已完全加载,否则 getListView().getCount() 将返回 0。例如,如果您在 onCreate 中使用它,我将无法工作。
如果您想在启动时执行此操作,我建议您在 onWindowFocusChanged 方法中执行此操作。
I took the idea of Udinic, but I improved it a little.
It is now possible to set the color of (in this case) the PreferenceCategory at any time, and not only when inflating the view.
How To do it ?
First, create your customized class such as this one :
Once it is done, you have to use it while defining your settings in XML.
After you just have to use this loop in your java preferenceActivity :
Here is the idea. You can do that for any of your settings, and at anytime.
The layout must have been totally loaded before using this code, because otherwise, getListView().getCount() will return 0. I won't work if you use it in onCreate for exemple.
If you want to do that at startup, I suggest you to do that in the onWindowFocusChanged method.