Reputation: 135
I want set Transparent ActionBar. I have tried to edit xml but doesn't work . I am confused. This is my Styles.xml
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
can you make me an simple example for this? See here: https://i.sstatic.net/JrrWl.png I have tried this code but doesn't work..
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));
Logcat in Eclipse doesn't show a error... app crash
Upvotes: 0
Views: 131
Reputation: 26198
You need to do it before the setContentView
not after it or youll get an error.
solution:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#000000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#000000ff")));
setContentView(R.layout.activity_main); //do it before this
Upvotes: 1