下面是我当前设置的屏幕截图。Android自定义操作栏删除图标
我创建了一个自定义操作栏视图,我在下面的代码设置,并且我想是两个图像,一个在左边的标题栏排列,其他的右对齐。
问题是,当我隐藏应用程序图标时,它只会隐藏它,不会删除它,因此左边的空白。我发现了一些其他的SO问题,展示了如何删除图标,但这也删除了我想保留的选项卡。
任何人都可以为我提供解决方案吗?
从我的onCreate()函数:
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.action_bar_title, null);
View homeIcon = findViewById(android.R.id.home);
((View) homeIcon.getParent()).setVisibility(View.GONE);
((View) homeIcon).setVisibility(View.GONE);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setCustomView(v);
我的XML定制布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="fill_horizontal"
android:layout_marginLeft="0dp"
android:orientation="horizontal"
>
<ImageView android:id="@+id/title_img_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/test" />
<ImageView android:id="@+id/title_img_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/test" />
</RelativeLayout>
我使用Holo.Light.DarkActionBar主题,我相信。
这没有iPhone。操作栏中的按钮应该位于右侧。 – bofredo
所以,试试用你自己的风格继承sherlock widget吧 – deadfish
@bofredo我不明白iPhone与任何东西有什么关系。他们不是按钮,他们是图像,这就是我希望他们在Android的设计 – TomP89