ActionBar波纹效果在后退按钮上起作用,但在菜单项上不起作用

时间:2019-06-21 02:16:30

标签: android android-fragments android-actionbar android-toolbar android-collapsingtoolbarlayout

我在<?xml version="1.0" encoding="utf-8"?> <layout xmlns:app="http://schemas.android.com/apk/res-auto"> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="400dp" android:id="@+id/appBar" android:fitsSystemWindows="true"> <com.google.android.material.appbar.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="match_parent" app:contentScrim="@color/colorWhite" app:layout_scrollFlags="scroll|exitUntilCollapsed" android:fitsSystemWindows="true"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" android:src="@drawable/background_image"/> </androidx.constraintlayout.widget.ConstraintLayout> <androidx.appcompat.widget.Toolbar android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" android:id="@+id/toolbar" app:title=" " app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> </androidx.appcompat.widget.Toolbar> </com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.AppBarLayout> <androidx.core.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorWhite" app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/large_text"/> </LinearLayout> </androidx.core.widget.NestedScrollView> </androidx.coordinatorlayout.widget.CoordinatorLayout> </layout> 上的菜单项上获得连锁反应时遇到麻烦。工具栏的后退按钮具有涟漪效应,但菜单项则没有。

enter image description here

这是我的布局结构

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setHasOptionsMenu(true)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    val binding = FragmentTestBinding.inflate(inflater, container, false)
    return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)

    (activity as AppCompatActivity).setSupportActionBar(toolbar)
    (activity as AppCompatActivity).supportActionBar?.apply {
        setDisplayShowHomeEnabled(true)
        setDisplayHomeAsUpEnabled(true)
    }

}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
    inflater.inflate(R.menu.share, menu)
}

我像往常一样在Fragment内部初始化。我应该做些特别的事情还是想念什么?

{{1}}

0 个答案:

没有答案