【问题标题】:Set elevation still display shadow below ActionBar in Android在Android中设置高程仍然在ActionBar下方显示阴影
【发布时间】:2016-10-25 10:14:43
【问题描述】:

values/styles.xml 内部,我已将<item name="elevation">0dp</item> 设置为我的AppTheme 样式。在values-21/styles.xml 里面我设置了<item name="android:elevation">0dp</item> 我也试过这个 <item name="android:windowContentOverlay">@null</item>.我也尝试过Clean 项目和Rebuild 项目。并尝试Invalidate Caches and Restart。但是我的模拟器仍然显示阴影,请参阅下面的屏幕。

问题:

如何将下面的阴影移除到ActionBar

屏幕截图:

【问题讨论】:

  • 撤消您在问题中描述的所有内容,并将android:elevation="0dp" 放在工具栏元素的 XML 布局中。
  • @Budius 我正在使用ActionBar,我尝试了这个但不起作用。
  • meokrvrenref rfe freiuvrwnei ewfwfijweofewfew fewfjewoifew stackoverflow.com/a/34348138
  • ActionBar 已弃用。工具栏长存
  • @Budius 文档在哪里。现在设置它,它只对我来说是阴影创建问题。

标签: android xml android-layout android-studio android-actionbar


【解决方案1】:

如果这是一个纯 ActionBar,而不是 Toolbar。这就是你的做法:

<style name="MyAppTheme" parent="Theme.AppCompat.Light">
  <item name="actionBarStyle">@style/FlatActionBar</item>
</style>

<style name="FlatActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid">
  <item name="elevation">0dp</item>
</style>

【讨论】:

  • 根据您的问题,您在应用主题中使用了elevation。这必须在应用于 actionBarStyle 的自定义样式中使用
  • @Ironman 尝试使用不同的方法:StateListAnimator stateListAnimator = new StateListAnimator(); stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(appBarLayout, "elevation", 0)); appBarLayout.setStateListAnimator(stateListAnimator);
【解决方案2】:

我不知道为什么elevationstyle 中不起作用。但是当我以编程方式设置它时它工作正常。

 getSupportActionBar().setElevation(0);

输出:

【讨论】:

  • 我也一样...不知道为什么会这样。
【解决方案3】:

把你的工具栏放在这里。

<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>

【讨论】:

  • 我没有使用ToolBar
猜你喜欢
  • 2016-08-06
  • 1970-01-01
  • 2011-11-24
  • 2015-07-05
  • 2022-12-13
  • 1970-01-01
  • 2015-02-14
相关资源
最近更新 更多