我删除了AppBarLayout。在运行时,我将工具栏的标高设置为0。它对我有用。
styles.xml
style name="AppTheme.AppBarOverlay"
parent="ThemeOverlay.AppCompat.Dark.ActionBar"
style name="AppTheme.PopupOverlay"
parent="ThemeOverlay.AppCompat.Light"
fragment_container.xml
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/appBarLayout"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
我在onCreate callback 中使用以下代码添加工具栏
var pageLayoutContainer=activity.getLayout充气器((.flupt(NativeSFR.layout.page_container_layout,null(;
fragmentLayoutContainer.findViewById(R.id.fragmentRootLayout);
toolbar = fragmentLayoutContainer.findViewById(R.id.toolbar);
activity.setSupportActionBar(toolbar);
actionBar = activity.getSupportActionBar();
我想删除工具栏下的阴影。但下面的代码对我不起作用。我的设备api级别大于21。
actionBar.setElevation(0);
试试这个:
AppBarLayout appBarLayout = findViewById(R.id.appBarLayout);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
appBarLayout.setElevation(getResources().getDimension(R.dimen.elevation));
}
getSupportActionBar().setElevation(0);
但我不明白为什么提升0不起作用(使用AppBarLayout(。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorYellow"
android:elevation="4dp"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
android:background="@color/colorYellow"
android:id="@+id/page_layout"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</RelativeLayout>
试试这个:-
ViewCompat.setElevation(View, int);
或
getSupportActionBar().setElevation(0);