0

I need a help about to find a theme who fits in this part of my project, but first I believe is nice to explain first the structure of the activities to find the answer:

Example of project style

  • The main activity (left) don't have any Action Bar, because takes to much space from screen an the Action Bar, polluted the design and is useless in this point.
  • The main activity, depending on the option of user, can go to 2 others activities, but both of them are kind of the same of the right activity(not eeeequal equal... is just to explain.) that consists in a Action Bar on top with the text of the result, a button back, one fixed part with some informations, and a Tab Layout with 3 tabs, each one, is a fragment.

the problem starts obviously, in this second activity...

I followed this site to build the screen at first: https://www.androidhive.info/2015/09/android-material-design-working-with-tabs/

but, with this site, they use this style:

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">

But using this style, with what i need, the result is this error:

 android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.TabLayout

So, to try to find the answer, i find this site over here: http://geeksmember.blogspot.com.br/2015/10/errorerror-inflating-class.html

Who shows me this solution on styles file:

<style name="AppTheme.Base" parent="android:Theme.Material">

Is a nice solution, is nice because in this moment i can separe the main style from the other style. Ok... buuuuut... when i start the aplication, comes this error:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

so... that's my question... because, when i use the "Theme.AppCompat.Light.DarkActionBar" comes the first error again... and i stay on this situation who i can't find a style who doesn't match with my needs...

If anyone needs the style file... (this is the style file for all the activities except the main activity)

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppTheme" parent="AppTheme.Base" />

    <style name="AppTheme.Base" parent="***I Need a theme here, i know, this is my question*** :)">
        <item name="android:colorPrimary">#212121</item>
        <item name="android:colorPrimaryDark">#000000</item>
        <item name="android:colorAccent">#303030</item>
    </style>

    <style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
        <item name="tabIndicatorColor">#80CBC4</item>
    </style>
</resources>

1 Answers1

1

You have two choices:

Use a different theme for your two activities

To do this, you'd create an "action bar theme" and a "no action bar theme":

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">#212121</item>
    <item name="colorPrimaryDark">#000000</item>
    <item name="colorAccent">#303030</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

Then, in your manifest, you'd assign the first theme to your app, and the second theme to any screen you didn't want an action bar for:

<application
    ...
    android:theme="@style/AppTheme">

    <activity
        android:name=".MainActivity"
        android:theme="@style/AppTheme.NoActionBar">

        ...
    </activity>

</application>

So this way, all screens will have an action bar by default, but any activity that should not have an action bar can be set up by specifying AppTheme.NoActionBar for that single activity.

Use a toolbar widget when you want an action bar

For this approach, you'd create your app theme to have no action bar:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">#212121</item>
    <item name="colorPrimaryDark">#000000</item>
    <item name="colorAccent">#303030</item>
</style>

Then, in any activity that should have an action bar, you'd add a Toolbar to your activity's layout:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

In your activity's onCreate() method, after setting your content view, you'd tell the system to use this toolbar as the action bar:

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Ben P.
  • 52,661
  • 6
  • 95
  • 123
  • I Have made the action bar customized worked in other screen, i make a layout and i called in code using: getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(R.layout.menu_telas); [... rest of code etc...] – Eloise Boatto Mar 02 '18 at 01:03
  • My question is: the toolbar you implemented here is to replace the TabLayout or to replace the Action Bar? i don´t get it... – Eloise Boatto Mar 02 '18 at 01:05