[英]Transparent action bar
I had to develop transparent action bar. 我不得不开发透明的动作栏。 After some research I was able to achieve the desired result only on LG2 device.
经过一些研究,我仅在LG2设备上就能达到预期的结果。 When i run the code on LG3 it's not working (action bar not transperent).
当我在LG3上运行代码时,它不起作用(操作栏无法透明显示)。
That's how my style folder looks: 这就是我的样式文件夹的外观:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:itemBackground">@color/black</item>
<item name="android:textColor">@color/white</item>
</style>
<style name="AppTheme.ActionBar.Transparent" parent="AppTheme">
<item name="android:windowContentOverlay">@null</item>
<item name="windowActionBarOverlay">true</item>
<item name="colorPrimary">@android:color/transparent</item>
</style>
</resources>
Someone has a suggestion how to solve this issue ? 有人建议如何解决这个问题?
You just need to define style having no actionbar
. 您只需要定义没有
actionbar
样式actionbar
。 Use toolbar and set its color transparent. 使用工具栏并将其颜色设置为透明。
<!-- Your App Theme -->
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- Your custom ActionBar Style -->
<style name="CustomActionBar" parent="@style/MyMaterialTheme.Base">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
Your ` 您的`
toolbar.xml
工具栏
<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"
app:theme="@style/CustomActionBar"/>
Use this toolbar
in any layout. 在任何布局中使用此
toolbar
。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Toolbar should be above content-->
<include layout="@layout/toolbar" />
</RelativeLayout>
` `
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.