我有一个位于android.support.design.widget.AppBarLayout
顶部的按钮
但按钮在布局显示和设备上留在它后面
我如何把按钮放在它前面?
或者在另一个问题中如何在右上方的屏幕选项菜单旁边添加一个按钮?
这是我的布局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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="apps.radwin.wintouch.activities.alignmentActivities.WorkordersSelectionActivity"
tools:showIn="@layout/app_bar_workorders_selection">
<Button
android:id="@+id/filterButtonMainWorkorderSelection"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="50dp"
android:layout_marginTop="20dp"
android:background="@drawable/ic_filter_list_black_24dp"
android:text=""
android:textSize="30dp" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabsLayoutWorkorderSelection"
android:layout_width="match_parent"
style="@style/TabLayoutStyle"
android:layout_height="wrap_content"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/workorderSelectionMainViewPagerContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="@drawable/add_workorders_plus"
android:layout_marginLeft="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_margin"
android:layout_marginBottom="@dimen/fab_margin"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="true"
android:background="#293339"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/fab">
<TextView
android:id="@+id/workorderFilterPopup_showAllText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:gravity="center"
android:paddingTop="5dp"
android:text="SHOW ALL"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textSize="20dp" />
<Button
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:id="@+id/filter_menu_workorders_show_all"
android:background="@color/transparent"
android:layout_marginLeft="10dp"
android:paddingTop="5dp"
/>
<ImageView
android:id="@+id/workorderFilterPopup_showAllCheckMark"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true"
android:src="@drawable/ic_done_black_24dp" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:id="@+id/workorderFilterPopup_showAllTextLine"
android:background="@color/white"
android:layout_below="@+id/workorderFilterPopup_showAllText"
></View>
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/ic_alarm_black_24dp"
android:id="@+id/workorderFilterPopup_plannedImage"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_showAllTextLine"
android:layout_alignParentStart="true" />
<Button
android:layout_width="match_parent"
android:layout_height="35dp"
android:id="@+id/filter_menu_workorders_planned"
android:background="@color/transparent"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_showAllTextLine"
android:layout_alignParentStart="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Planned"
android:textColor="@color/white"
android:layout_marginLeft="20dp"
android:id="@+id/workorderFilterPopup_plannedText"
android:layout_alignBottom="@+id/workorderFilterPopup_plannedImage"
android:layout_toEndOf="@+id/workorderFilterPopup_plannedImage" />
<ImageView
android:id="@+id/workorderFilterPopup_PlannedCheckMark"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/workorderFilterPopup_plannedText"
android:src="@drawable/ic_done_black_24dp" />
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/ic_cloud_off_black_24dp"
android:id="@+id/workorderFilterPopup_incompleteImage"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_plannedImage"
android:layout_alignParentStart="true" />
<Button
android:layout_width="match_parent"
android:layout_height="35dp"
android:id="@+id/filter_menu_workorders_incomplete"
android:background="@color/transparent"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_plannedImage"
android:layout_alignParentStart="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Uncompleted"
android:textColor="@color/white"
android:layout_marginLeft="20dp"
android:id="@+id/workorderFilterPopup_intompleteText"
android:layout_alignBottom="@+id/workorderFilterPopup_incompleteImage"
android:layout_toEndOf="@+id/workorderFilterPopup_incompleteImage" />
<ImageView
android:id="@+id/workorderFilterPopup_IncompleteCheckMark"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/workorderFilterPopup_intompleteText"
android:src="@drawable/ic_done_black_24dp" />
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/ic_cloud_queue_black_24dp"
android:id="@+id/workorderFilterPopup_CompleteImage"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_incompleteImage"
android:layout_alignParentStart="true" />
<Button
android:layout_width="match_parent"
android:layout_height="35dp"
android:id="@+id/filter_menu_workorders_complete"
android:background="@color/transparent"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_incompleteImage"
android:layout_alignParentStart="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="complete 5"
android:textColor="@color/white"
android:layout_marginLeft="20dp"
android:id="@+id/workorderFilterPopup_completeText"
android:layout_alignBottom="@+id/workorderFilterPopup_CompleteImage"
android:layout_toEndOf="@+id/workorderFilterPopup_CompleteImage" />
<ImageView
android:id="@+id/workorderFilterPopup_completeCheckMark"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/workorderFilterPopup_completeText"
android:src="@drawable/ic_done_black_24dp" />
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_below="@+id/workorderFilterPopup_CompleteImage"
></View>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
答案 0 :(得分:1)
将按钮包裹在Cardview内,并为Cardview增高一些。我尝试了以下代码:(使用Textview而不是Button)
<androidx.cardview.widget.CardView
android:id="@+id/filterButtonMainWorkorderSelection"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="50dp"
app:cardBackgroundColor="@color/colorPrimaryDark"
app:cardElevation="6dp"
android:layout_marginTop="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_flash_auto_black_24dp"
android:textSize="30dp" />
</androidx.cardview.widget.CardView>
答案 1 :(得分:0)
在APPBARLAYOUT顶部放置按钮
在您的布局中,您使用的是工具栏,它占据了布局的最高位置。如果您想要工具栏顶部的 按钮 ,那么。
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:theme="@style/AppTheme.AppBarOverlay">
<Button
android:id="@+id/filterButtonMainWorkorderSelection"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="50dp"
android:layout_marginTop="20dp"
android:background="@drawable/ic_filter_list_black_24dp"
android:text=""
android:textSize="30dp" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabsLayoutWorkorderSelection"
android:layout_width="match_parent"
style="@style/TabLayoutStyle"
android:layout_height="wrap_content"
/>
</android.support.design.widget.AppBarLayout>
如果您希望它位于工具栏下方,请将按钮放在工具栏下方。
答案 2 :(得分:0)
您在布局中使用了工具栏,这占据了布局的最高位置。如果您希望按钮位于工具栏的顶部,则将按钮放在<android.support.v7.widget.Toolbar/>
标签之间。像这样:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
<Button
android:id="@+id/filterButtonMainWorkorderSelection"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="50dp"
android:layout_marginTop="20dp"
android:background="@drawable/ic_filter_list_black_24dp"
android:text=""
android:textSize="30dp" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabsLayoutWorkorderSelection"
android:layout_width="match_parent"
style="@style/TabLayoutStyle"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
这应该给您想要的结果
答案 3 :(得分:0)
关于为什么不显示按钮,可能有两个问题,顺序和高度。
您的工具栏的默认标高为4dp
。
所以我建议您尝试做:
AppBarLayout
后Toolbar
的海拔,请注意,如果问题是海拔,则放置视图的顺序无关紧要。我在下面做了两项更改(海拔高度为6dp),因此您可以简单地复制粘贴您的布局文件:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="apps.radwin.wintouch.activities.alignmentActivities.WorkordersSelectionActivity"
tools:showIn="@layout/app_bar_workorders_selection">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabsLayoutWorkorderSelection"
android:layout_width="match_parent"
style="@style/TabLayoutStyle"
android:layout_height="wrap_content"
/>
</android.support.design.widget.AppBarLayout>
<Button
android:id="@+id/filterButtonMainWorkorderSelection"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="50dp"
android:elevation="6dp"
android:layout_marginTop="20dp"
android:background="@drawable/ic_filter_list_black_24dp"
android:text=""
android:textSize="30dp" />
<android.support.v4.view.ViewPager
android:id="@+id/workorderSelectionMainViewPagerContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="@drawable/add_workorders_plus"
android:layout_marginLeft="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_margin"
android:layout_marginBottom="@dimen/fab_margin"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="true"
android:background="#293339"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/fab">
<TextView
android:id="@+id/workorderFilterPopup_showAllText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:gravity="center"
android:paddingTop="5dp"
android:text="SHOW ALL"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textSize="20dp" />
<Button
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:id="@+id/filter_menu_workorders_show_all"
android:background="@color/transparent"
android:layout_marginLeft="10dp"
android:paddingTop="5dp"
/>
<ImageView
android:id="@+id/workorderFilterPopup_showAllCheckMark"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true"
android:src="@drawable/ic_done_black_24dp" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:id="@+id/workorderFilterPopup_showAllTextLine"
android:background="@color/white"
android:layout_below="@+id/workorderFilterPopup_showAllText"
></View>
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/ic_alarm_black_24dp"
android:id="@+id/workorderFilterPopup_plannedImage"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_showAllTextLine"
android:layout_alignParentStart="true" />
<Button
android:layout_width="match_parent"
android:layout_height="35dp"
android:id="@+id/filter_menu_workorders_planned"
android:background="@color/transparent"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_showAllTextLine"
android:layout_alignParentStart="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Planned"
android:textColor="@color/white"
android:layout_marginLeft="20dp"
android:id="@+id/workorderFilterPopup_plannedText"
android:layout_alignBottom="@+id/workorderFilterPopup_plannedImage"
android:layout_toEndOf="@+id/workorderFilterPopup_plannedImage" />
<ImageView
android:id="@+id/workorderFilterPopup_PlannedCheckMark"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/workorderFilterPopup_plannedText"
android:src="@drawable/ic_done_black_24dp" />
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/ic_cloud_off_black_24dp"
android:id="@+id/workorderFilterPopup_incompleteImage"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_plannedImage"
android:layout_alignParentStart="true" />
<Button
android:layout_width="match_parent"
android:layout_height="35dp"
android:id="@+id/filter_menu_workorders_incomplete"
android:background="@color/transparent"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_plannedImage"
android:layout_alignParentStart="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Uncompleted"
android:textColor="@color/white"
android:layout_marginLeft="20dp"
android:id="@+id/workorderFilterPopup_intompleteText"
android:layout_alignBottom="@+id/workorderFilterPopup_incompleteImage"
android:layout_toEndOf="@+id/workorderFilterPopup_incompleteImage" />
<ImageView
android:id="@+id/workorderFilterPopup_IncompleteCheckMark"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/workorderFilterPopup_intompleteText"
android:src="@drawable/ic_done_black_24dp" />
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/ic_cloud_queue_black_24dp"
android:id="@+id/workorderFilterPopup_CompleteImage"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_incompleteImage"
android:layout_alignParentStart="true" />
<Button
android:layout_width="match_parent"
android:layout_height="35dp"
android:id="@+id/filter_menu_workorders_complete"
android:background="@color/transparent"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_below="@+id/workorderFilterPopup_incompleteImage"
android:layout_alignParentStart="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="complete 5"
android:textColor="@color/white"
android:layout_marginLeft="20dp"
android:id="@+id/workorderFilterPopup_completeText"
android:layout_alignBottom="@+id/workorderFilterPopup_CompleteImage"
android:layout_toEndOf="@+id/workorderFilterPopup_CompleteImage" />
<ImageView
android:id="@+id/workorderFilterPopup_completeCheckMark"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="20dp"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/workorderFilterPopup_completeText"
android:src="@drawable/ic_done_black_24dp" />
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_below="@+id/workorderFilterPopup_CompleteImage"
></View>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
答案 4 :(得分:0)
为此,您必须使用膨胀选项菜单,而menu.xml文件将如下所示
$ gawk 'BEGIN { print strtonum("160"), strtonum("0160") }'
160 112
我希望这会帮助您尝试错误的方法,否则请使用自定义布局创建自己的应用栏
答案 5 :(得分:0)
在RelativeLayout
中,XML中的最后一个子元素覆盖了先前定义的所有其他内容。您在这里面临的问题是因为XML的Z顺序不是您所需要的。
要解决此问题,您需要将Button
声明移到AppBarLayout
声明下方。这是代码段
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="apps.radwin.wintouch.activities.alignmentActivities.WorkordersSelectionActivity"
tools:showIn="@layout/app_bar_workorders_selection">
<!--First declare the AppBarLayout-->
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabsLayoutWorkorderSelection"
android:layout_width="match_parent"
style="@style/TabLayoutStyle"
android:layout_height="wrap_content"
/>
</android.support.design.widget.AppBarLayout>
<!--Your button goes here just before the ViewPager-->
<Button
android:id="@+id/filterButtonMainWorkorderSelection"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="50dp"
android:layout_marginTop="20dp"
android:background="@drawable/ic_filter_list_black_24dp"
android:text=""
android:textSize="30dp" />
<android.support.v4.view.ViewPager
android:id="@+id/workorderSelectionMainViewPagerContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
其余的XML可以保持不变。
编辑:您可以更详细地了解这个概念here。