私は、自分のタブレイアウトアクティビティの上部に表示するカスタムツールバーを作成しました。私のアクティビティのxmlにそれを含めた後、それは、自分のタブレイアウトの異なるフラグメントタブに背景色(ORANGE)として機能します。Android Custom ToolBarは画面全体をカバーします
ツールバーXML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@color/ColorPrimary"
android:id="@+id/toolbar_clashmate"
android:elevation="4dp">
</android.support.v7.widget.Toolbar>
TabLayout活動のXML(どこ上部のツールバーを追加する)私の活動のトップにそれを設定する方法
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#dfdfdf"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/PrimaryColor"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tabs"
/>
</RelativeLayout>
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
/>
</FrameLayout>
さらにそれにボタンを追加できますか?
を使用することができます。代わりにラップコンテンツを使用する –
ツールバーに 'android:layout_width =" match_parent "'と 'android:layout_height ="?attr/actionBarSize "'を使用する – rafsanahmad007