让用户选择主题 [Android]
我正在开发一个应用程序,我试图让用户更改“主题”或布局的外观。就像某些应用程序可以选择“浅色主题”或“深色主题”一样。
所以基本上我需要以下方面的帮助:
- Android 中有我可以使用的内置主题吗?
- 我如何访问主题?
- 任何其他有用的信息。我对此真的很陌生。
I'm have an app i'm working on in which I'm trying to let the user change the "theme" or the look of the layouts. Like how some apps have the option where you can pick the "Light theme" or the "Dark Theme".
So basically I need help with the following:
- Are there any built in themes in Android that I can use?
- How do I get access to the themes?
- Any other useful information. I'm really new at this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用标准 Android theme/style 流程创建主题,并构建您想要提供给用户的主题/资源列表(例如,“Light”=> R.style.MyLightTheme、“Dark”=> R.style.MyDarkTheme、“iPhone”=> ; R.style.iOSTheme)。例如,将可用主题列表作为首选项/设置屏幕中的
ListPreference
向用户公开。在 Activity 的
onCreate()
方法中,在调用setContentView()
之前,使用this.setTheme(customTheme);
customTheme
来自共享首选项如上所述You would need to create your themes using the standard Android theme/style process, and build a list of the Themes/resources you want to make available to the user (e.g., "Light" => R.style.MyLightTheme, "Dark" => R.style.MyDarkTheme, "iPhone" => R.style.iOSTheme). Expose that list of available themes to the user as, for example, a
ListPreference
in a Preferences/Settings screen.In your Activity's
onCreate()
method(s), before callingsetContentView()
, set the theme usingthis.setTheme(customTheme);
customTheme
would come from the shared preferences as mentioned above