【发布时间】:2014-06-14 09:27:07
【问题描述】:
我创建了一个带有自定义 xml 布局的操作栏,该布局应该具有透明背景。它在 ICS 上正常工作,但在 KitKat 上它有灰色背景而不是透明度。谁能帮我解决这个问题并使操作栏对所有 Android 版本 4 及更高版本都是透明的?
这里是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>
这是我使用的代码:
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);
【问题讨论】:
标签: android android-actionbar android-xml android-theme