让用户选择一个主题[机器人]机器人、主题、用户

2023-09-05 04:37:00 作者:單裑

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

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(),通过设置主题this.setTheme(customTheme);

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

customTheme 将来自的共享preferences 的上述