【发布时间】:2012-10-15 18:44:17
【问题描述】:
我正在使用 actionbarsherlock。
为了获得底部的动作模式(action modes on bottom)我使用
android:uiOptions="splitActionBarWhenNarrow"
但我需要在主操作栏上添加一个按钮,所以我使用自定义视图。
View customNav = LayoutInflater.from(this).inflate(R.layout.custom_view, null);
getSupportActionBar().setCustomView(customNav, new
ActionBar.LayoutParams(Gravity.RIGHT));
getSupportActionBar().setDisplayShowCustomEnabled(true);
这里是 custom_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal"
>
<ImageButton
android:id="@+id/btnMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_day"
android:onClick="onMoreClick"/>
如果我使用具有相同属性的 ImageButton 或 ImageView 没有关系,所以我将讨论 ImageButton。
如果我使用 ImageButton,我会得到我想要的,除了背景是灰色的。
如果我在之前的 custom_view.xml 中添加一行,以获得透明背景(或改用 ImageView)
android:background="#00000000"
图标中的 alpha 将被“裁剪”并且按钮的大小将发生变化。
问题是。如何获得具有第一张图像(默认灰色背景)但具有透明背景的大小的按钮?
解决问题的方法之一是让按钮的背景颜色与操作栏的颜色相同,看起来像透明的,但我认为这不是一个好的解决方案。
【问题讨论】:
标签: android android-actionbar actionbarsherlock android-custom-view