0
votes

In my Application I want on all Activities except Activity with material design sliding tabs to have ActionBar. If I want to make material design sliding tabs I need in my style to use:

 parent="Theme.AppCompat.Light.NoActionBar" 

but with this code I won't have ActionBar on other Activities which I want....

styles.xml

     <resources>    
    <!-- Base application theme. -->
    <style name="AppTheme"  parent="Theme.AppCompat.Light.NoActionBar">
    </style>    
    </resources>

tool_bar.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:background="@color/ColorPrimary"
    android:elevation="2dp"
    android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"

    xmlns:android="http://schemas.android.com/apk/res/android" />

So should I create two styles in resources or what?

1

1 Answers

0
votes

The best way is add it in your AndroidManifest file. You can apply a theme to any activity by including android:theme inside <activity> inside manifest file.

For example:

<activity android:theme="@android:style/Theme.Dialog">
<activity android:theme="@style/CustomTheme">

And if you want to set theme programatically then use setTheme() before calling setContentView() and super.onCreate() method inside onCreate() method.

To set it programmatically in Activity.java:

public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setTheme(R.style.MyTheme); // (for Custom theme)
  setTheme(android.R.style.Theme_Holo); // (for Android Built In Theme)

  this.setContentView(R.layout.myactivity);