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);
...
}
...
}