[英]How to remove the shadow under Action bar
I have been trying to get the shadow under the app Action bar to disappear but it wont which is very annoying. 我一直在尝试使应用程序“动作”栏下的阴影消失,但它不会很烦人。 iI have set the theme to NoActionBar and opted to using toolbar instead.
我已将主题设置为NoActionBar并选择改为使用工具栏。
And have i have also set the elevation to 0dp in my activity.java 并在我的activity.java中将海拔高度设置为0dp吗
package com.example.drawerlayout;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.appcompat.widget.Toolbar;
import com.google.android.material.appbar.AppBarLayout;
public class MainActivity extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mToggle;
private Toolbar mToolbar;
private AppBarLayout actionLayout;
private Toolbar t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close);
mToolbar = (Toolbar) findViewById(R.id.nav_action);
setSupportActionBar(mToolbar);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setElevation(0);
}
}
The Toolbar looks thus: 工具栏如下所示:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/nav_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/mm_blue" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Set this property toolbar:elevation="0dp"
to AppBarLayout
to remove shadow from Toolbar
. 将此属性
toolbar:elevation="0dp"
为AppBarLayout
以从Toolbar
删除阴影。 eg- 例如-
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
toolbar:elevation="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/nav_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/mm_blue" />
</com.google.android.material.appbar.AppBarLayout>
Simply add app:elevation="0dp"
只需添加
app:elevation="0dp"
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<!-- Toolbar -->
</com.google.android.material.appbar.AppBarLayout>
Check below code 检查下面的代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
app:elevation="0dp">
<androidx.appcompat.widget.Toolbar
android:id="@+id/nav_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/mm_blue" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Just remove the AppBar layout and directly put your toolbar in the coordinate layout: 只需删除AppBar布局,然后将您的工具栏直接放在坐标布局中即可:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/nav_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/mm_blue" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Try this may it should help you out. 试试这个可能对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.