Android 如何删除应用程序图标和ActionBar屏幕边缘之间的边距?
我的应用程序有一个自定义主页图标,我希望它一直与actionbar的左侧对齐,这样它就可以接触到屏幕的边缘。这有可能吗?如果有,怎么做?我没有看到任何设置填充或边距以使其一直向左对齐的内容。我终于找到了这个。您需要使用自定义的actionbar视图。其实很简单: (这是使用ActionbarSherlock,它还应该与stock compat库一起使用…)Android 如何删除应用程序图标和ActionBar屏幕边缘之间的边距?,android,android-3.0-honeycomb,android-actionbar,Android,Android 3.0 Honeycomb,Android Actionbar,我的应用程序有一个自定义主页图标,我希望它一直与actionbar的左侧对齐,这样它就可以接触到屏幕的边缘。这有可能吗?如果有,怎么做?我没有看到任何设置填充或边距以使其一直向左对齐的内容。我终于找到了这个。您需要使用自定义的actionbar视图。其实很简单: (这是使用ActionbarSherlock,它还应该与stock compat库一起使用…) 首先,在res/values/themes.xml中,将actionbar显示选项设置为“custom”: 基本上就是这样!如果我遗漏
- 首先,在res/values/themes.xml中,将actionbar显示选项设置为“custom”:
主图标上是否有填充物或边距??如果是,请将其移除。顺便说一句,给我们看一些xml文件中的代码,这里的许多代码可以帮助您解决这个问题。这里没有xml。刚刚将android:icon=“@drawable/my_icon”添加到清单和ab.setDisplayShowHomeEnabled(true);ab.setDisplayUseLogoEnabled(假);对于Activity,您不需要设置homeicon布局参数,只需将@+id/home_图标上的边距设置为0(而不是如示例所示的5dp)。@OnuraySahin您可以在代码中设置相同的选项
<item name="android:displayOptions">showCustom</item>
<ImageView
android:id="@+id/home_icon"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:scaleType="centerCrop"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<!-- Add textviews or whatever you like here to replicate the actionbar
title etc. -->
View mActionCustomView = getSherlockActivity().getLayoutInflater()
.inflate(R.layout.actionbar_layout, null);
getSherlockActivity().getSupportActionBar().setCustomView(
mActionCustomView);
ImageView homeIcon = (ImageView)mActionCustomView
.findViewById(R.id.home_icon);
int abHeight = getSherlockActivity().getSupportActionBar()
.getHeight();
homeIcon.setLayoutParams(new RelativeLayout.LayoutParams(
abHeight, abHeight));