嗨我想从我的工具栏中删除API 21及更高版本的高程和阴影效果.以下是我的尝试
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setElevation(0);
Run Code Online (Sandbox Code Playgroud)
我的XML工具栏.我试图将高程设置为0dp
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:elevation="0dp"
android:theme="@style/ToolbarStyle"
app:theme="@style/ToolbarStyle"
>
Run Code Online (Sandbox Code Playgroud)
如果有帮助的话,这就是ToolbarStyle
<style name="ToolbarStyle" parent="ThemeOverlay.AppCompat.Dark">
<item name="colorControlNormal">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
编辑1:在样式v21中尝试以下操作.还是一样的结果
<style name="ToolbarStyle" parent="ThemeOverlay.AppCompat.Dark">
<item name="colorControlNormal">@android:color/white</item>
<item name="android:elevation">0dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
编辑2:工具栏在我的布局中
android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/toolbar" />
Run Code Online (Sandbox Code Playgroud)
Fil*_*usa 109
你可以通过简单的步骤做到这一点.不要android.support.design.widget.AppBarLayout从布局中删除,而是将属性添加到布局中app:elevation="0dp".您的最终布局将是:
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
...
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
chr*_*hry 11
这个删除工具栏上的高程(android:stateListAnimator ="@ null"),stateListAnimator是API级别21或更高,所以插入工具道具(在命名空间声明之前),如下所示:
//xmlns:tools="http://schemas.android.com/tools" in parent or start element
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stateListAnimator="@null"
android:theme="@style/AppTheme.AppBarOverlay"
tools:targetApi="21">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:elevation="0dp"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
//your content goes here like RecyclerView, Card or other layout
Run Code Online (Sandbox Code Playgroud)
这是我的示例结果:
只需删除这部分布局层次结构:
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
Run Code Online (Sandbox Code Playgroud)
它负责创建阴影.工具栏本身不会投射任何阴影.
小智 5
转到要删除ActionBar的Elevation的活动.在setContent(....)之前,请求ActionBar功能(即如果你没有直接声明它)
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getSupportActionBar().setElevation(0);
Run Code Online (Sandbox Code Playgroud)
或者只是调用声明的工具栏变量,例如toolbar.setElevation(0);
app:elevation="0dp"在您的AppBarLayout中使用。确保像这样将工具栏放入AppBarLayout中-
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/AppTheme.AppBarOverlay"
android:fitsSystemWindows="true"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/firstOption"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
并将此行添加到您的活动中- findViewById(R.id.appBarLayout).bringToFront();
这会将AppBar置于最前面。
| 归档时间: |
|
| 查看次数: |
34703 次 |
| 最近记录: |