6

ライブラリhttps://github.com/futuresimple/android-floating-action-buttonを使用して、非常にうまく機能するファブ ボタンを作成しています。私はいくつかのライブラリを試しましたが、ほとんどのアプリケーションでファブ (または keep、inbox などの Google アプリ) で使用される効果を使用するものはありません。ファブをクリックすると、アプリケーション全体の背景が半透明の白または黒になります。私はそれを行う方法を見つけることができません。この種の効果を行うための例またはそのようなものを持つことは可能ですか? この画像で私が何を意味するかを見ることができます: ここに画像の説明を入力

半黒背景

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

    <RelativeLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/semi_white_bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white_semi_transparent"
        android:visibility="gone" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/listFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/content_frame"
        android:visibility="gone" >

        <TextView
            android:id="@+id/status"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/cabinet_color"
            android:fontFamily="sans-serif"
            android:gravity="center_vertical"
            android:paddingBottom="8dp"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:paddingTop="8dp"
            android:textColor="#fff"
            android:textSize="17sp"
            android:visibility="gone" />

        <android.support.v7.widget.RecyclerView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/status"
            android:clipToPadding="false"
            android:scrollbars="vertical" />

        <LinearLayout
            android:id="@android:id/empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/emptyImage"
                android:layout_width="96dp"
                android:layout_height="96dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="16dp"
                android:scaleType="fitXY"
                android:src="?empty_image" />

            <TextView
                android:id="@+id/emptyText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:fontFamily="sans-serif-light"
                android:gravity="center"
                android:lineSpacingMultiplier="1.4"
                android:paddingBottom="16dp"
                android:text="@string/no_files"
                android:textColor="?empty_text"
                android:textSize="22sp" />
        </LinearLayout>
    </RelativeLayout>

    <ProgressBar
        android:id="@android:id/progress"
        style="?android:progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:indeterminateOnly="true" />

</RelativeLayout>

これは私のlayout.xmlですが、私が望むようにまったく機能していないようです。

4

4 に答える 4

5

私の意見では、これが最も簡単な解決策であることがわかり、完全に機能します。

fam.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
        @Override
        public void onMenuExpanded() {
            dimmedBackground.setVisibility(View.VISIBLE);
        }

        @Override
        public void onMenuCollapsed() {
            dimmedBackground.setVisibility(View.GONE);
        }
    });
于 2015-04-13T13:02:03.243 に答える
2

あなたの質問が気に入りました...

このライブラリでは、追加ボタンのクリック イベントを設定することはできません。独自のライブラリ コードを変更する必要がある場合があります。このアイデアを使用してください。Relatie またはフレームレイアウトを使用して、黒い背景または画像を FAB の後ろに追加します。

ライブラリ クラス FloatingActionsMenu.class で、次のコードを見つけてコメントします。

//mAddButton.setOnClickListener(new OnClickListener()
//{
//  @Override
//  public void onClick(View v)
//  {
//      toggle();
//  }
//});

次に、このメソッドをそのクラスに追加し、

public void setAddButtonClickListener(OnClickListener listener)
{
mAddButton.setOnClickListener(listener);
}

次のようにアクティビティでクリックリスナーを定義します

OnClickListener listener = new OnClickListener()
{
    @Override
    public void onClick(View v)
    {
        if (floatingActionMenuButton.isExpanded())
        {//make the background visible
        }
        else
        {//make the background invisible
        }
        floatingActionMenuButton.toggle();
    }
};

FABに渡す

floatingActionMenuButton.setAddButtonClickListener(listener);

ライブラリとプロジェクトをビルドします。これが役立つことを願っています!

于 2015-03-30T13:03:04.743 に答える
1

アクティビティを FrameLayout でラップする必要があります。FrameLayout には 2 つの子が必要です

  • あなたの活動内容
  • FloatingActionsMenu を含む別の Framelayout

関連するコード スニペットを次に示します。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.city.bytes.view.MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <!-- other content in the activity -->
</LinearLayout>

<FrameLayout
    android:id="@+id/frame_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white_overlay">
    <!--  floating action menu with buttons -->
</FrameLayout>

frame_layoutアクティビティで、 FAB メニューがクリックされたときのアルファを変更します。解説ブログも書いています。http://www.rishabhsinghal.in/implement-floating-action-button-similar-to-inbox-by-gmail-or-evernote/

于 2015-08-22T11:58:08.440 に答える