让用户选择一个主题[机器人] [英] Let the user choose a theme [Android]

查看:134
本文介绍了让用户选择一个主题[机器人]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序我工作中,我试图让用户改变主题或布局的外观。像一些应用程序怎么也得在那里你可以选择轻主题或黑暗的主题选项。

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:

  • 是否有任何内置的主题,在Android中,我可以使用?
  • 如何获得访问的主题?
  • 在任何其他有用的信息。我真的在这个新的。

推荐答案

您需要使用标准的 Android的主题/风格的过程,并建立你想提供给用户(例如,在主题/资源列表光=> R.style.MyLightTheme,黑暗=> R .style.MyDarkTheme,iPhone=> R.style.iOSTheme)。揭露可用的主题是清单给用户,例如目录preference 在preferences /设置屏幕。

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.

在你活动的的onCreate()办法(S),之前调用的setContentView(),通过设置主题<一href="http://developer.android.com/reference/android/view/ContextThemeWrapper.html#setTheme%28int%29"><$c$c>this.setTheme(customTheme);

In your Activity's onCreate() method(s), before calling setContentView(), set the theme using this.setTheme(customTheme);

customTheme 将来自的共享preferences 的上述

这篇关于让用户选择一个主题[机器人]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆