I have created a actionbar with a custom xml layout that should have a transparent background. It works as it should on ICS but on KitKat it has a gray background instead of the transparency. Can anyone help me solve this issue and make the actionbar transparent for all Android versions 4 and up?
Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_actionbar_layout"
android:background="@android:color/transparent"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<ImageButton
android:id="@+id/action_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:contentDescription="@string/app_name"
android:padding="5dp"
android:src="@drawable/menu" />
<ImageButton
android:id="@+id/action_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:contentDescription="@string/app_name"
android:padding="5dp"
android:src="@drawable/settings" />
<ImageButton
android:id="@+id/action_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/action_settings"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/action_settings"
android:background="@android:color/transparent"
android:contentDescription="@string/app_name"
android:padding="5dp"
android:src="@drawable/share" />
<com.quanticapps.athan.views.RobotoTextView
android:id="@+id/action_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/app_name"
android:textColor="@android:color/white" />
</RelativeLayout>
And here is the code that I use:
final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater()
.inflate(R.layout.main_actionbar, null);
// Set up your ActionBar
final ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(actionBarLayout);
// Typeface mTypeface = Typeface.createFromAsset(getAssets(),
// "rockwell.ttf");
title = (TextView) findViewById(R.id.action_title);
share = (ImageButton) findViewById(R.id.action_share);
settings = (ImageButton) findViewById(R.id.action_settings);
menu = (ImageButton) findViewById(R.id.action_menu);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
title.setTextSize(15);
title.setGravity(Gravity.CENTER);