在Android的工具栏顶部查看

时间:2016-05-03 06:43:34

标签: android-layout

我有一个完美的导航抽屉,但在选择一个导航菜单时(请参考下图),工具栏顶部会添加一个视图。

这是我的片段布局

www.example.com/your-page.html?active-tab={your_active_tab_id}

图像:

the view added on top

这是我的抽屉xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/random_check_layout"
android:layout_height="match_parent"
android:orientation="vertical">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="false">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/randomCheckDescription"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="40dp"
            android:layout_marginTop="30dp"
            android:gravity="center"
            android:text="This scans the barcode of any existing business"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.3"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/txtRandomCheckBacode"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="12dp"
                    android:inputType="text"
                    android:hint="barcode"
                    android:textColorHint="@color/edit_text_hint"
                    android:textColor="@color/edit_text"
                    android:paddingLeft="10dp"
                    android:paddingBottom="10dp"
                    android:background="@drawable/edit_text_bottom_border"
                    android:layout_marginLeft="20dp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.7"
                android:orientation="horizontal"
                android:weightSum="1">

                <ImageButton
                    android:id="@+id/btnScanBarcode"
                    android:layout_width="fill_parent"
                    android:layout_height="28dp"
                    android:text="@string/scan_hint"
                    android:layout_marginRight="20dp"
                    android:background="@color/white"
                    android:textColor="@color/white"
                    android:layout_marginLeft="2dp"
                    android:src="@drawable/ic_scan"
                    android:contentDescription="@string/scan_hover" />

            </LinearLayout>

        </LinearLayout>

        <android.support.v7.widget.AppCompatButton
            android:id="@+id/btnRandomCheckSubmit"
            android:layout_width="fill_parent"
            android:layout_height="35dp"
            android:layout_marginTop="80dp"
            android:text="Proceed"
            android:background="@drawable/custom_button"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:textColor="@color/white"
            android:foreground="?android:selectableItemBackground" />

    </LinearLayout>
</ScrollView> </LinearLayout>

主要活动xml。

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android">



    <item android:title="My Dashboard"
          android:id="@+id/nav_item_home"
          android:icon="@drawable/ic_home"/>

    <item android:title="Random Check"
        android:id="@+id/nav_item_random_check"
        android:icon="@drawable/random_check"/>

    <item android:title="Verify Reference"
          android:id="@+id/nav_item_verify_receipt"
          android:icon="@drawable/verify_receipts"/>

    <item android:title=" Meter Reading"
          android:id="@+id/nav_item_meter_reading"
          android:icon="@drawable/meter_reading"/>

    <group android:id="@+id/group_settings_id">
        <item android:title="Help"
            android:id="@+id/nav_item_help"
             android:icon="@drawable/help"/>
    </group>
        <item android:title="Logout"
            android:id="@+id/nav_item_logout"
            android:icon="@drawable/logout"/>



</menu>

1 个答案:

答案 0 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <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/base_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>

        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"></FrameLayout>

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_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:itemIconTint="@color/colorPrimary"
        app:menu="@menu/navigation_menu_item" />

</android.support.v4.widget.DrawerLayout>

style.xml如下:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>