小编fre*_*v20的帖子

FloatingActionButton不隐藏

我试图以fabLocation编程方式隐藏我的FloatingActionButton :

fabLocation.setVisibility(View.GONE)
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

如果我添加android:visibility="gone"我的XML布局,fabLocation当我运行我的活动时会隐藏它,但是当我滚动时它会重新出现.

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/colorOverlay"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/img_couverture"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/bg_navigation_drawer_header"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.CardView
            android:layout_marginTop="8dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="16dp">

                <TextView
                    android:id="@+id/tv_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="18sp" />

                <View …
Run Code Online (Sandbox Code Playgroud)

android material-design floating-action-button android-design-library

40
推荐指数
6
解决办法
4万
查看次数

在嵌套片段中使用OptionsMenu

我使用在hostactivity MenuActivity中实现的NavigationDrawer模式。我的导航有3个项目:项目1,项目2,项目3。每个项目都绑定到一个片段。

当我单击项目1时,我显示了一个片段A,该片段实现了具有多个片段(嵌套片段)的ViewPager。

在我的嵌套片段中,我使用以下方法为菜单充气(效果很好!):

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.my_menu, menu);
    super.onCreateOptionsMenu(menu, inflater);
}
Run Code Online (Sandbox Code Playgroud)

但是,当我单击菜单的另一个元素(项目2->显示片段B或项目3->显示片段C)时,菜单(在嵌套片段中膨胀了)始终可见,但我希望它消失。

您对此问题有解决方案吗?先感谢您。

android nested menu fragment

5
推荐指数
1
解决办法
1954
查看次数