【问题标题】:ImageButton(ImageView) in custom layout for actionbarsherlockactionbarsherlock 的自定义布局中的 ImageButton(ImageView)
【发布时间】: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


    【解决方案1】:

    您可以使用具有透明背景的图像。可以在 Photoshop 中完成。

    【讨论】:

    • 呃,什么?我使用来自Action Bar Icon Pack 的图像在 Photoshop 中我应该如何处理它们?
    【解决方案2】:

    您是否考虑过使用 ImageView 而不是 ImageButton?只需在图像视图中设置所需的图像,然后使用 onclicklistener 来检测点击,就像对 ImageButton 所做的那样。

    此外,您还可以指定 ImageButton 的宽度并根据需要设置填充(如果您想使用 android:background="#00000000")。

    【讨论】:

      【解决方案3】:

      我认为你可以添加到按钮

      android:background="yourimagethere";或者可能是 android:background=NULL

      它会解决问题

      【讨论】:

        猜你喜欢
        • 2013-01-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多