Um die alte Actionbar in einer ActionbarActivity auszublenden, bietet sich an, folgendes als Style zum Beispiel in der themes.xml
anzugeben:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="BaseTheme" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
</style>
</resources>
Die Toolbar muss natürlich anschließend in jeder Activity eingebaut werden:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=MainActivity">
<include layout="@layout/toolbar_transparent"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:theme="@style/Exoplanets.Actionbar.Color"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Die aktuell benutzte Toolbar muss dann noch in der Activity gesetzt werden:
public class MainActivity extends ActionBarActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set view
setContentView(R.layout.activity_main);
// get toolbar
toolbar = (Toolbar) findViewById(R.id.toolbar);
// setup action bar
setSupportActionBar(toolbar);
}
}
Ich habe hier die Android-Support-Bibliothek verwendet.