【问题标题】:How to check whether a specific drawable is present or not in FAB programatically?如何以编程方式检查 FAB 中是否存在特定的可绘制对象?
【发布时间】:2018-03-01 11:09:24
【问题描述】:

我有 FAB 按钮,点击时我需要获取 FAB 的当前源

下面是代码:

  fab_progress_image = (FloatingActionButton) findViewById(R.id.fab_progress_image);
fab_progress_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Drawable sDraw = getResources().getDrawable(R.mipmap.ic_keyboard_voice_black_24dp);

                if(fab_progress_image.getBackground() == sDraw){
                }
                }
                }

我保留了这张支票,但不知何故它不起作用。

下面是布局文件:

             <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_progress_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_keyboard_voice_black_24dp"
        android:layout_alignParentRight="true"
        app:elevation="6dp"
        android:layout_centerVertical="true"
        app:pressedTranslationZ="12dp"
        app:backgroundTint="@color/theme_color"
        app:fabSize="mini"
        android:layout_marginRight="10dp"

        />

请建议如何在没有标志的情况下检查 FAB 的现有图标

【问题讨论】:

  • 你能澄清一下这个问题吗?点击按钮后你想获取什么?

标签: android floating-action-button


【解决方案1】:

我相信你需要比较drawables的内容(像素),请检查这个问题:Comparing resources within two drawables

【讨论】:

    猜你喜欢
    • 2019-01-05
    • 1970-01-01
    • 2011-04-05
    • 2021-01-13
    • 1970-01-01
    • 2013-10-23
    • 1970-01-01
    • 2021-11-06
    • 2012-09-13
    相关资源
    最近更新 更多