如何在android中更改fab菜单按钮图像

时间:2016-11-28 09:08:51

标签: xml android-studio android-drawable floating-action-button

screenshot of fab buttons in xml我正在使用'com.github.clans:fab:1.6.4'库来显示fab按钮,它们工作正常但是当我尝试更改按钮的图像时,图像显示为非常小,fab菜单按钮的图像根本没有变化。 有谁能告诉我如何解决这个问题?

这是xml代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="none" >
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <TableLayout
            android:layout_marginTop="10dp"
            android:id="@+id/tabla_cuerpo"
            android:layout_width="match_parent"
            android:layout_height="362dp">

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#BCBCBC">

                <TextView
                    android:id="@+id/textView1a"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#BCBCBC"                android:padding="5dp"
                    android:text="Case#"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

                <TextView
                    android:id="@+id/textView1b"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#BCBCBC"                android:padding="5dp"
                    android:text="Client"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

                <TextView
                    android:id="@+id/textView1c"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#BCBCBC"                android:padding="5dp"
                    android:text="Case Amount"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
                <TextView
                    android:id="@+id/textView1d"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#BCBCBC"                android:padding="5dp"
                    android:text="Received"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
                <TextView
                    android:id="@+id/textView1e"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#BCBCBC"                android:padding="5dp"
                    android:text="Reminder"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
                <TextView
                    android:id="@+id/textView1f"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#BCBCBC"                android:padding="5dp"
                    android:text="Remarks"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                  <TextView

                android:id="@+id/textView2a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/cellshape"
                android:padding="5dp"
                android:text="Case#"
                android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

                <TextView
                    android:id="@+id/textView2b"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cellshape"
                    android:padding="5dp"
                    android:text="Client"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

                <TextView
                    android:id="@+id/textView2c"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cellshape"
                    android:padding="5dp"
                    android:text="Case Amount"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
                <TextView
                    android:id="@+id/textView2d"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cellshape"
                    android:padding="5dp"
                    android:text="Received"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
                <TextView
                    android:id="@+id/textView2e"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cellshape"
                    android:padding="5dp"
                    android:text="Reminder"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
                <TextView
                    android:id="@+id/textView2f"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cellshape"
                    android:padding="5dp"
                    android:text="Remarks"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
            </TableRow>
            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView

                    android:id="@+id/textView3a"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cellshape"
                    android:padding="5dp"
                    android:text="Case#"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

                <TextView
                    android:id="@+id/textView3b"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cellshape"
                    android:padding="5dp"
                    android:text="Client"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

                <TextView
                    android:id="@+id/textView3c"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cellshape"
                    android:padding="5dp"
                    android:text="Case Amount"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
                <TextView
                    android:id="@+id/textView3d"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cellshape"
                    android:padding="5dp"
                    android:text="Received"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
                <TextView
                    android:id="@+id/textView3e"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cellshape"
                    android:padding="5dp"
                    android:text="Reminder"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
                <TextView
                    android:id="@+id/textView3f"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/cellshape"
                    android:padding="5dp"
                    android:text="Remarks"
                    android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
            </TableRow>

        </TableLayout>

    </LinearLayout>
</HorizontalScrollView>

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/fab_menu"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:paddingBottom="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        fab:menu_backgroundColor="#ccffffff"
        fab:fab_colorNormal="#DA4336"
        fab:fab_colorPressed="#E75043"
        fab:fab_colorRipple="#99FFFFFF"
        fab:fab_showShadow="true"
        fab:menu_labels_colorNormal="#333333"
        fab:menu_labels_colorPressed="#444444"
        fab:menu_labels_colorRipple="#66FFFFFF"
        fab:menu_labels_showShadow="true"
        fab:menu_labels_maxLines="-1"
        fab:menu_labels_position="left"
        fab:menu_openDirection="up"
        fab:fab_shadowColor="#66000000"
        fab:menu_labels_ellipsize="end"
        fab:menu_labels_singleLine="true">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/add_payment_btn"
            fab:fab_label="ADD PAYMENT"
            fab:fab_size="mini" />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/editcasesicon"
            fab:fab_label="EDIT PAYMENT"
            fab:fab_size="mini" />

    </com.github.clans.fab.FloatingActionMenu>
</FrameLayout>

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/delete"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="30dp"
    android:layout_marginBottom="21dp"
    />
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

我只是使用相同的库。将你的可绘制图像大小设置为24dp高度和24dp width.am发布我的示例代码屏幕截图。我希望​​它对你有用。

你不要同时使用和 一次只使用任何一个FloatingActionButton。否则在声明控件[FloatingActionButton]期间引发错误。 enter image description here enter image description here

如果你想chnage FloatingActionMenu图像,那么你可以从你的库项目中更改图像drawable,打开FloatingActionMenu.class并从该文件行编号。 161无论你想要什么,都可以改变你的形象......