如何更改 Android 偏好设置的文本颜色?

发布于 2024-10-05 04:57:38 字数 689 浏览 0 评论 0原文

我想将 Android 应用程序的首选项屏幕的外观更改为白色背景和深色文本颜色。看来我可以在代码中更改背景颜色。是否有类似的方法来更改代码中首选项的文本颜色?

getListView().setBackgroundColor(Color.TRANSPARENT);
getListView().setCacheColorHint(Color.TRANSPARENT);
getListView().setBackgroundColor(Color.rgb(255, 255, 255));

另一种方法可以是在应用程序清单中将活动的主题设置为亮起:

android:theme="@android:style/Theme.Light"

但是,这会覆盖应用程序的样式,当前设置为

android:theme="@android:style/Theme.NoTitleBar"

“因此,标题栏显示在首选项屏幕中”。我可以尝试

requestWindowFeature(Window.FEATURE_NO_TITLE);

通过尝试打开首选项时应用程序崩溃(AndroidRuntimeException:在添加内容之前必须调用 requestFeature())来删除该栏。

I want to change the look of my Android app's preference screen to white background and dark text color. It seems that I can change background color in the code. Is there a similar way to change text color of preferences in the code?

getListView().setBackgroundColor(Color.TRANSPARENT);
getListView().setCacheColorHint(Color.TRANSPARENT);
getListView().setBackgroundColor(Color.rgb(255, 255, 255));

The other way could be setting the activity's theme to light in the app's manifest:

android:theme="@android:style/Theme.Light"

However, this overrides the application's style, which currently is set to

android:theme="@android:style/Theme.NoTitleBar"

Thus, title bar is displayed in the preferences screen. I can try to remove the bar by

requestWindowFeature(Window.FEATURE_NO_TITLE);

The app then crashes (AndroidRuntimeException: requestFeature() must be called before adding content) when trying to open preferences.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拿命拼未来 2024-10-12 04:57:38

使用 Theme.Light.NoTitleBar :)

Use Theme.Light.NoTitleBar :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文