9

実際、私は FAB の受信トレイを模倣する方法を探しています。ユーザーが赤いボタンを押すと、不透明なビューとメニューが表示されます。画像の方がより意味があるため、次の図を参照してください

ここに画像の説明を入力

この素晴らしいライブラリ ( https://github.com/futuresimple/android-floating-action-button )が存在することを知っており、このライブラリを使用すると、フローティング アクション メニューを表示できます。しかし、私の問題は白い背景を表示することです(不透明)。問題を解決するための解決策が見つかりませんでした...

事前にThx

4

4 に答える 4

17

他のビューの上に配置され、幅と高さが親と一致するFloatingActionMenu内側を配置します。FrameLayout同じマージンを使用して、メニューを持ち上げて右からオフセットします。

OnFloatingActionsMenuUpdateListenerフローティング アクション メニューに設定します。メソッド内のフレーム レイアウトの背景色を切り替え/置換するようになりました。

 @Override
 void onMenuExpanded(){
  mFrameLayoutWrapper.setBackgroundColor(mAlpaWhite);
  }

  @Override
  void onMenuCollapsed(){
    mFrameLayoutWrapper.setBackgroundColor(Color.TRANSPARENT);
  }
于 2015-01-16T20:18:59.497 に答える
0

今おっしゃった効果は以下の方法で実現しました。フローティング ボタンの後ろと他のレイアウトの上にビューを追加し、メニューが展開されるまでビューの可視性を維持します。次に、ビューの可視性を VISIBLE に設定します。はい、ビューの背景を任意の不透明な色に設定します。

私のコード

私のXMLファイル

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:text="Other View here"
    android:textSize="50dp"
    android:layout_centerHorizontal="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<View
    android:id="@+id/background_dimmer"
    android:visibility="gone"
    android:background="#55000000"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<com.getbase.floatingactionbutton.FloatingActionsMenu
    android:id="@+id/multiple_actions"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    fab:fab_addButtonColorNormal="@color/white"
    fab:fab_addButtonColorPressed="@color/white_pressed"
    fab:fab_addButtonPlusIconColor="@color/half_black"
    fab:fab_labelStyle="@style/menu_labels_style"
    android:layout_marginBottom="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginEnd="16dp">

    <com.getbase.floatingactionbutton.FloatingActionButton
        android:id="@+id/action_a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:fab_colorNormal="@color/white"
        fab:fab_title="Action A"
        fab:fab_colorPressed="@color/white_pressed"/>

</com.getbase.floatingactionbutton.FloatingActionsMenu>

そして、FloatingButtons が処理されるアクティビティまたはフラグメントで

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    setFloatingButtonControls();
}

private void setFloatingButtonControls(){
    this.bckgroundDimmer = findViewById(R.id.background_dimmer);
    this.floatingActionsMenu = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
    this.floatingActionsMenu.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
        @Override
        public void onMenuExpanded() {
            bckgroundDimmer.setVisibility(View.VISIBLE);
        }

        @Override
        public void onMenuCollapsed() {
            bckgroundDimmer.setVisibility(View.GONE);
        }
    });
}

これにより、必要な効果が得られます。お役に立てれば。それは確かに私を助けました。:)

于 2015-10-05T17:24:53.023 に答える
0

ツールバー、フローティング メニュー、コンテンツ、相対レイアウトを備えた 1 つのコーディネーター レイアウトを使用します。相対レイアウトの背景色を白透明に設定し、可視性を Gone に設定します。「NoActionBar」テーマを設定し、アクティビティでアクション バーの代わりにツールバーを使用します。フローティング メニューを開くたびに、相対レイアウトの可視性を表示に設定し、閉じると非表示に戻します。

于 2016-05-27T12:34:58.183 に答える