简体   繁体   English

自定义Android appcompat操作栏:如何删除v11 +设备上的底部边框

[英]Custom Android appcompat Actionbar: how to remove bottom border on v11+ devices

I'm using the Android appcompat library to create a custom action bar. 我正在使用Android appcompat库来创建自定义操作栏。 That all works. 这一切都有效。 On devices not using the v11 theme (values folder) a bottom border does not appear as it should not. 在不使用v11主题(值文件夹)的设备上,不显示底部边框,因为它不应该出现。 But when v11+ devices use the theme (in the values-v11 folder of course) there is a bottom border. 但是当v11 +设备使用主题时(当然在values-v11文件夹中)有一个底部边框。 It's a thin 1dp type border. 它是一个薄的1dp类型边框。 I have a custom background applied for the actionbar and this all works on version < v11, just an annoying extra bottom border is added on v11+ devices ;-] 我有一个自定义背景应用于操作栏,这一切都适用于版本<v11,只是在v11 +设备上添加了一个恼人的额外底部边框; - ]

Now I found via another SO article where the user was using ActionBarSherlock that the base theme needed to be Theme.X and not theme.X.Light.x to resolve this issue (with no explanation as to why). 现在我通过另一篇SO文章发现用户使用ActionBarSherlock,基本主题需要是Theme.X而不是theme.X.Light.x来解决这个问题(没有解释为什么)。 I applied this same logic (I'm using android's appcompat, not sherlock one) and it worked for removing the border but then other style issues came up with radio buttons, etc, taking on the non-light theme. 我应用了这个相同的逻辑(我使用的是android的appcompat,而不是sherlock)并且它可以用于删除边框但是其他样式问题出现了单选按钮等,采用非轻量级主题。 So I want to keep the base theme as 'Theme.AppCompat.Light' and get rid of the bottom border on the actionbar. 所以我想将基本主题保持为'Theme.AppCompat.Light'并摆脱操作栏上的底部边框。 Again, it doesn't show up on devices < v11. 同样,它不会出现在设备<v11上。

Screen shots (Theme.AppCompat.Light/Theme.AppCompat): 屏幕截图(Theme.AppCompat.Light / Theme.AppCompat):

My theme (same in values folder minus the android prefacing): 我的主题(在值文件夹中减去android前置相同):

    <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Application theme. -->
    <style name="ActionTheme" parent="@style/Theme.AppCompat.Light">           
        <item name="android:actionBarStyle">@style/ActionBarStyle</item>         
        <item name="android:windowActionBar">true</item>  
    </style>

   <style name="ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">     
       <item name="android:displayOptions"></item>           
        <item name="android:background">@drawable/header_style</item>         
         <item name="android:titleTextStyle">@style/ActionBarTitleText</item>  
        <item name="android:layout_height">wrap_content</item> 
        <item name="android:layout_width">wrap_content</item>   
        <item name="android:height">70dp</item> 
     </style>

    <style name="ActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/color_dark_blue</item>           
    </style>     
</resources>

Through the power of SO my question was finally answered! 通过SO的力量,我的问题终于得到了回答! I tried everything the OP in the below link tried and more over the last two days. 在过去的两天里,我尝试了以下链接中的OP尝试的所有内容。 Somehow I didn't see this SO thread (I wasn't using search terms 'divider', methinks). 不知怎的,我没有看到这个SO线程(我没有使用搜索术语'divider',methinks)。

What worked for me was to have the no window overlay property set to null. 对我有用的是将no window overlay属性设置为null。 I see that setting the window color may work on some higher version of android (4.2.x+) as well, so I decided to set both. 我看到设置窗口颜色也可以在更高版本的android(4.2.x +)上工作,所以我决定设置两者。 Here is the SO link with the solution(s) to this nasty feature (bug?): link 这是SO链接与这个令人讨厌的功能(bug?)的解决方案: 链接

My final values-v11/themes.xml - 我的最终价值-v11 / themes.xml -

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Application theme. -->
    <style name="ActionTheme" parent="@style/Theme.AppCompat.Light">           
        <item name="android:actionBarStyle">@style/ActionBarStyle</item>         
        <item name="android:windowActionBar">true</item>  
        <item name="android:windowBackground">@android:color/white</item> 
        <item name="android:windowContentOverlay">@null</item>
    </style>

   <style name="ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">     
       <item name="android:displayOptions"></item>           
        <item name="android:background">@drawable/header_style</item>         
         <item name="android:titleTextStyle">@style/ActionBarTitleText</item>  
        <item name="android:layout_height">wrap_content</item> 
        <item name="android:layout_width">wrap_content</item>   
        <item name="android:height">70dp</item>  
     </style>

    <style name="ActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/color_dark_blue</item>           
    </style>     
</resources>

If user2545146 answer doesn't work on lollipop. 如果user2545146回答不适用于棒棒糖。

call setElevation on the actionbar from the activity. 从活动中调用操作栏上的setElevation。

getSupportActionBar().setElevation(0);

The only thing that worked for me was 唯一对我有用的是

AppBarLayout appBarLayout = findViewById(R.id.my_app_bar_layout);
appBarLayout.setOutlineProvider(null);

api >= 21 only api> = 21

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

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