我怎样才能获得android中浮动动作按钮的图像类型视图?

时间:2017-01-24 09:35:20

标签: android android-layout floating-action-button

我知道如何设置浮动动作按钮,如下图所示。但是我需要在点击时显示不同的布局,或者当我想要显示该布局时。附上第二个布局

我怎样才能实现这个目标?

1 个答案:

答案 0 :(得分:1)

请参阅此链接浮动操作按钮工具栏https://github.com/AlexKolpa/fab-toolbar

您需要在项目中添加依赖项。

compile 'com.github.alexkolpa:floating-action-button-toolbar:0.5.1'

在您的XML文件中

<com.github.alexkolpa.fabtoolbar.FabToolbar
android:id="@+id/fab_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
tb:tb_anim_duration="500"
tb:tb_button_gravity="end"
tb:tb_container_gravity="center"
>

<ImageView
    android:id="@+id/attach"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_attachment_white_48dp"
    android:layout_marginLeft="@dimen/icon_margin"
    android:layout_marginRight="@dimen/icon_margin"
    />

<!-- More buttons can be added here -->

要隐藏或显示工具栏,只需致电hide()show()

FabToolbar fabToolbar = ((FabToolbar) findViewById(R.id.fab_toolbar));

findViewById(R.id.attach).setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        fabToolbar.hide();
    }
});