Nee*_*ava 14 android tabbar android-layout android-toolbar
我正在尝试制作一个应用程序,其中标签栏,导航抽屉和搜索所有都在工具栏下,但当我尝试在tabbar页面标题分开时
我想在哪里显示其他片段的标题也是布局代码
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Boss.Main2Activity">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/bg_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY" />
<com.antonyt.infiniteviewpager.InfiniteViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<me.alexrs.fontpagertitlestrip.lib.FontPagerTitleStrip
android:id="@+id/titlestrip"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginEnd="50dp"
android:layout_marginStart="50dp"
android:background="@color/material_fragment_top"
app:fontFamily="@font/font"
app:theme="@style/AppTheme.PopupOverlay" />
</com.antonyt.infiniteviewpager.InfiniteViewPager>
<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="50dp"
app:theme="@style/CustomActionBar" />
<include layout="@layout/content_main2" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
我希望布局在导航抽屉和搜索之间显示导航抽屉和标签栏以及搜索栏图标和页面标题,因为您可以看到它分离得太多.我试图使工具栏像黑色播放器应用程序
现在我在 Black Player 应用程序中看到的是,您想要的标题完全相同是自定义的。从我的角度来看,导航按钮不是默认按钮,它是其点击抽屉上的一张图像,可以打开和关闭。因此,在下面给出的 XML 中,我只是创建一个自定义顶部栏,在这种情况下它是一个relativelayout,如果您看到它具有操作栏的默认高度。现在,您需要在 java 文件中做一件事,您需要从那里隐藏工具栏,以便自定义 topBar 将自动出现在其顶部。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
tools:context="com.bodaciousithub.myapplication.Main5Activity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:src="@drawable/ic_menu_black_24dp"
android:layout_centerVertical="true"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/imageView"
android:background="?attr/colorPrimary"
android:layout_toLeftOf="@id/imageView2"
app:popupTheme="@style/AppTheme.PopupOverlay"
android:layout_toEndOf="@id/imageView"
android:layout_toStartOf="@id/imageView2"
app:tabMode="scrollable">
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab1"/>
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab2"/>
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab3"/>
</android.support.design.widget.TabLayout>
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="@drawable/ic_search_black_24dp"
android:layout_alignParentEnd="true"
android:layout_marginRight="8dp"
android:layout_alignParentRight="true" />
</RelativeLayout>
<include layout="@layout/content_main5" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
最后一个包含布局语句是添加显示内容的主布局。AppBar 布局是导航视图中的默认布局,因此在 java 文件中我将其隐藏。你可以写getSupportActionBar().hide()或者getActionBar().hide()
下面是我制作的布局的屏幕截图。
希望有帮助!
| 归档时间: |
|
| 查看次数: |
359 次 |
| 最近记录: |