如何以编程方式检查FAB中是否存在特定的drawable?

问题描述 投票:0回答:1

我有FAB按钮,在onclick上我需要获取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个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.