我试过了this。但我面临的问题是<item name="android:windowActionBarOverlay">true</item>
滑动标签位于操作栏后面。
(参见标签上方的标识和标题) 当我设置
android:layout_marginTop="?attr/actionBarSize"
然后滑动标签不会保持透明。
在没有滑动标签的情况下使操作栏透明的正确方法是什么?
编辑: activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/newbg">
<!-- The sliding tab -->
<com.github.amitt001.musicapp.stab.SlidingTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- The pager that allows us to swipe between fragments -->
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/transparent"/><!--#A6000000" -->
</LinearLayout>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:actionOverflowButtonStyle">@style/ActionButtonOverflow</item>
<!-- Support library compatibility -->
<item name="actionOverflowButtonStyle">@style/ActionButtonOverflow</item>
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="windowActionBarOverlay">true</item>
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@android:color/transparent</item>
<item name="background">@android:color/transparent</item>
</style>
<style name="ActionButtonOverflow" parent="@style/Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">@drawable/ic_drawer</item>
</style>
</resources>
答案 0 :(得分:2)
使用工具栏和标签创建一个xml
tool_bar_tabs.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:minHeight="?attr/actionBarSize"
android:background="@color/ColorPrimary"
android:elevation="4dp"
app:theme="@style/ToolbarColors">
</android.support.v7.widget.Toolbar>
<com.github.amitt001.musicapp.stab.SlidingTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/ColorPrimary</item>
<item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
</style>
your activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/newbg">
<include
android:id="@+id/tb_tabs"
layout="@layout/tool_bar_tabs"></include>
<!-- The pager that allows us to swipe between fragments -->
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/transparent"/><!--#A6000000" -->
</LinearLayout>
初始化。工具栏并将其设为
中的操作栏MainActivity
public class Main extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar tb = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(tb);
}