android - 使用 setDisplayHomeAsUpEnabled(true) 时如何设置 Home-Icon 边距?

标签 android android-actionbar android-homebutton

我对 native 操作栏(不是 ABS)有疑问。在正常状态下,图标两侧的边距为 26 像素。

enter image description here

但是当我调用 setDisplayHomeAsUpEnabled(true)它减少了这个边距,结果看起来更窄。

enter image description here

你知道如何在 setDisplayHomeAsUpEnabled(true) 时保持这个边距吗?叫做? (最好没有解决方法和自定义 View )

提前致谢

最佳答案

您可以像这样设置主页图标的边距:(只需在 Activity 的 onCreate(...) 方法中调用以下代码)

ImageView ivIcon = (ImageView) findViewById(android.R.id.home);

FrameLayout.LayoutParams lpIcon = (FrameLayout.LayoutParams) ivIcon.getLayoutParams();

lpIcon.topMargin = lpIcon.bottomMargin = yourmargin;
lpIcon.leftMargin = lpIcon.rightMargin = yourmargin;
ivIcon.setLayoutParams(lpIcon);

Its kind of a hack but I used it to get rid of the margin completely by setting it to 0.

关于android - 使用 setDisplayHomeAsUpEnabled(true) 时如何设置 Home-Icon 边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18588222/

相关文章:

android - 使用凭据从 Android App 调用 Google Endpoint 时没有任何反应

android - Xamarin Android - 操作栏图标填充

android - 如果您在一个 Activity 中,按下 Activity 主页按钮时会调用哪些生命周期方法?

Android:按“主页”或“后退”按钮停止播放

php - Android:使用 SSL/HTTPS 与 PHP 连接到数据库并使用 POST/GET

android - 如何设置 TabLayout ta 的圆形波纹形状?

java - 为什么 Android 会忽略 READ_SMS 权限?

android - 在 Android 寻呼机中隐藏应用程序标题栏

android - 操作栏不显示

java - 即使按下主页按钮或后退按钮,Android 应用程序也会重新打开并继续下一个 Activity