I would like to have a transparent actionbar with only two button on left and right.
for that I wrote in my Activity :
protected void onCreate(Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
if(getResources().getBoolean(R.bool.portrait_only)){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
actionBar = getSupportActionBar();
LayoutInflater mInflater = LayoutInflater.from(this);
actionBarView = mInflater.inflate(R.layout.actionbar_menu_button, null);
actionBar.setCustomView(actionBarView);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBarLeftButton = (ImageView) actionBar.getCustomView().findViewById(R.id.action_bar_left_button);
actionBarTitle = (TextView) actionBar.getCustomView().findViewById(R.id.actionbar_title);
actionBarRightButton = (ImageView) actionBar.getCustomView().findViewById(R.id.action_bar_right_button);
}
in style.xml I have :
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:textColor">@color/oeo_grey_5</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="Theme.AppCompat">
<item name="android:background">@color/oeo_transparent</item>
<item name="android:backgroundStacked">@android:color/transparent</item>
</style>
and my action bar layout is :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:paddingRight="20dp"
>
<ImageView
android:id="@+id/action_bar_left_button"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:clickable="false"
android:focusable="false"
android:longClickable="false"
android:src="@drawable/actionbar_menu_button"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
/>
<TextView
android:id="@+id/actionbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TITLE"
android:gravity="center"
android:textSize="18sp"
android:singleLine="true"
android:ellipsize="end"
android:textColor="@color/oeo_grey_2"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
<ImageView
android:id="@+id/action_bar_right_button"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:clickable="false"
android:focusable="false"
android:longClickable="false"
android:src="@drawable/actionbar_account_button"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
But I always have a kind of black / dark grey background even if the overlay setting works correctly. What did I miss?
UPDATE After looking to this link
I made the following modifications :
@Override
protected void onCreate(Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
if(getResources().getBoolean(R.bool.portrait_only)){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.oeo_transparent)));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.oeo_transparent)));
LayoutInflater mInflater = LayoutInflater.from(this);
actionBarView = mInflater.inflate(R.layout.actionbar_menu_button, null);
actionBar.setCustomView(actionBarView);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBarLeftButton = (ImageView) actionBar.getCustomView().findViewById(R.id.action_bar_left_button);
actionBarTitle = (TextView) actionBar.getCustomView().findViewById(R.id.actionbar_title);
actionBarRightButton = (ImageView) actionBar.getCustomView().findViewById(R.id.action_bar_right_button);
and it worked. (I was also able to remove the style MyActionBar from styles.xml)