0

I have an AppCompatActivity with transparent Toolbar. The problem is that on devices below API 21 the title and the arrow (up navigation) of the toolbar is transparent. I know it is there because clicking the invisable arrow brings me back to the last activity. Devices with API 21 and above show a white title and white back arrow.

My styles.xml (based on this answer)

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<!-- from https://stackoverflow.com/questions/29907615/android-transparent-status-bar-and-actionbar -->
<style name="AppTheme.Transparent" parent="AppTheme">
    <item name="android:windowContentOverlay">@null</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="colorPrimary">@android:color/transparent</item>
</style>

and my styles.xml(v21)

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:colorPrimary">@color/colorPrimary</item>
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:colorAccent">@color/colorAccent</item>
    <item name="android:windowContentTransitions">true</item>
</style>

<!-- from https://stackoverflow.com/questions/29907615/android-transparent-status-bar-and-actionbar -->
<style name="AppTheme.Transparent" parent="AppTheme">
    <item name="colorPrimary">@android:color/transparent</item>
</style>

The toolbar

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:elevation="4dp"
    android:fitsSystemWindows="true"
    app:theme="@style/ThemeOverlay.AppCompat.Dark"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

I also tried adding app:titleTextColor="@android:color/white" and wrapping the toolbar in an AppBarLayout. Without any success.

-----EDIT------
The important part of the AppCompatActivity

import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
...

public class DetailsActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_view);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        String title = ...
        getSupportActionBar().setTitle(title);
        ...
    }
    ...
}
Community
  • 1
  • 1
xani
  • 784
  • 1
  • 7
  • 21

1 Answers1

0

In You Activity.java import android.support.v7.widget.Toolbar instead of android.widget.Toolbar

In your Activity.java in onCreate()

    setContentView(R.layout.activity_main);

    //getting the support actionbar for api lower then 21
    getSupportActionBar().hide();

    toolbar = (Toolbar) findViewById(R.id.toolbar_view);
    setSupportActionBar(toolbar); 

you can also look into this android transparent action bar and status bar showing arrow

Community
  • 1
  • 1
Emdad Hossain
  • 387
  • 1
  • 3
  • 10
  • Thanks for the answer. Sadly it didn't help. I've already imported the `android.support.v7.widget.Toolbar`. I have added the important part of the code of the Avtivity the my main post. – xani Oct 18 '16 at 16:17
  • in your App theme in style.xml, add: `false` – Emdad Hossain Oct 18 '16 at 17:04
  • No change. Probably because my style is already derived from `*.NoActionBar`. – xani Oct 18 '16 at 17:18