0

I have FAB button in which on onclick i need to fetch the current source of the FAB

below is code :

  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){
                }
                }
                }

I have kept this check but somehow its not working.

below is the layout file:

             <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"

        />

Please suggest how to check existing icon of FAB without a flag

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Feroz Siddiqui
  • 3,840
  • 6
  • 34
  • 69
  • Can you clarify the question? What do you want to fetch after the button is clicked? – jle Mar 01 '18 at 12:46

1 Answers1

0

I believe you need to compare the content (pixels) of the drawables, please check this question: Comparing resources within two drawables

Mina Wissa
  • 10,923
  • 13
  • 90
  • 158