简体   繁体   中英

How do I change the theme of my app in android studio?

我从下拉菜单中的设计部分更改主题,如材质暗、全息等。我需要在样式部分编写代码来更改主题?

AndroidStudio 仅显示您自己以编程方式在应用程序中应用该主题时的外观。

In res/values/styles.xml you can add following code to change theme:

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
        <item name="windowNoTitle">true</item>
        <item name="android:colorPrimary">@color/colorPrimary</item>
        <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:colorAccent">@color/colorAccent</item>
        <item name="android:statusBarColor">@color/colorPrimaryDark</item>
        <item name="android:colorControlActivated">@color/colorPrimaryDark</item>
        <item name="android:colorControlHighlight">@color/colorPrimary</item>
        <item name="android:colorControlNormal">@color/colorPrimary</item>
        <item name="android:windowBackground">@color/colorBackground</item>
        
    </style>
</resources>

you can change theme by modifying parent attribute

您应该编辑应用程序清单并将android:theme属性添加到具有您想要的主题的应用程序或活动标签。

 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_second);
   if(mode.equals("dark")){
     setTheme(android.R.style.DarkTheme);
   }else if(mode.equals("light")){
     setTheme(android.R.style.LightTheme);
   }else{
     setTheme(android.R.style.AppTheme);
   }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM