简体   繁体   English

如何删除android动作栏Shadow

[英]How can I remove android actionbar Shadow

I'm using Android Studio for programming. 我正在使用Android Studio进行编程。 Target SDK is 23 and Minimum SDK is 15 目标SDK为23,最低SDK为15

I'm trying to remove the shadow between my actionbar and my sliding tab layout. 我正在尝试删除操作栏和滑动标签布局之间的阴影。 But I'm not able to. 但我无法做到。

Note : The shadow is only visible in Android 5 and upper. 注意:阴影仅在Android 5和更高版本中可见。

I have used <item name="elevation">0dp</item> and getSupportActionBar().setElevation(0); 我使用了<item name="elevation">0dp</item>getSupportActionBar().setElevation(0); But still it doesn't work... 但它仍然不起作用......

在此输入图像描述

My Style.xml 我的Style.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>



<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>



<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
    <item name="elevation">0dp</item>
</style>

My Style V21 我的风格V21

<resources>>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

My MainActivity.java onCreateCode: 我的MainActivity.java onCreateCode:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setElevation(0);

.... ....

You're missing the prefix in your style. 你错过了你风格的前缀。

<item name="android:elevation">0dp</item>

That said you could also set it directly on your AppBarLayout 也就是说你也可以直接在你的AppBarLayout上设置它

<android.support.design.widget.AppBarLayout 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:elevation="0dp"
    android:theme="@style/AppTheme.AppBarOverlay">

Or what I like to do is move the SlidingTabLayout into the AppBarLayout so the shadow appears below it: 或者我喜欢将SlidingTabLayout移动到AppBarLayout以便阴影显示在它下面:

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    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="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay"
        />

    <com.ccswe.SmokingLog.views.widgets.SlidingTabLayout
        android:id="@+id/sliding_tabs"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/tab_layout_height"
        />

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

上一个代码段的输出

Try adding setting the elevation to 0 with the help of the support library 尝试在支持库的帮助下将高程设置为0

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:elevation="0dp"
    android:theme="@style/AppTheme.AppBarOverlay">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM