简体   繁体   English

Android Studio中的导航抽屉模板

[英]Navigation Drawer Template in Android Studio

我在这个导航抽屉中完全感到困惑。我正在研究很多教程,但我不明白。我想如何使用android studio(Template)导航抽屉或如何使用导航抽屉使用列表视图(如果我们使用列表视图)然后在第一行中添加图像,然后在导航抽屉中添加仪表板片段。请提供任何参考或任何示例程序。

If you created an activity as Navigation Drawer Activity in Android Studio, Android Studio will be created a set of layout. 如果您在Android Studio中将活动创建为“导航抽屉活动”,则会为Android Studio创建一组布局。

  • activity_layout.xml (or the name of Activity) activity_layout.xml(或“活动”的名称)
  • app_bar.xml (for toolbar) app_bar.xml(用于工具栏)
  • content.xml (for content) content.xml(用于内容)
  • nav_header.xml (for header view of navigation drawer) nav_header.xml(用于导航抽屉的标题视图)

The first item of the navigation drawer (the first row of the list that you say) is nav_header.xml. 导航抽屉的第一项(您说的列表的第一行)是nav_header.xml。 In this layout you can set the first row. 在此布局中,您可以设置第一行。 Also on the menu folder is created a .xml, with activity_drawer.xml as name, with the items of navigation. 此外,在菜单文件夹上还创建了一个.xml,其名称为activity_drawer.xml,并带有导航项。

Something like this: 像这样:

activity_drawe.xml activity_drawe.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto">
   <item
    android:id="@+id/search"
    android:icon="@android:drawable/ic_menu_search"
    android:title="@string/drawer_search"
    app:actionViewClass="android.widget.SearchView"
    app:showAsAction="always" />

   <group android:title="@string/drawer_eltiempo"
       android:enabled="true"
       android:checkableBehavior="single">
    <item android:id="@+id/eltiempo"
          android:enabled="false"
          android:title="@string/drawer_eltiempo">
        <menu>
            <item
                android:id="@+id/tutiempo"
                android:title="@string/drawer_tutiempo"/>
            <item
                android:id="@+id/paises"
                android:title="@string/drawer_tiempoPaises"/>
            <item
                android:id="@+id/cercaTi"
                android:title="@string/drawer_cercaTi"/>
            <item
                android:id="@+id/web"
                android:title="@string/drawer_nuestraWeb"/>
            <item
                android:id="@+id/config"
                android:title="@string/drawer_configuracion"/>
        </menu>
    </item>
  </group>
</menu>

nav_header.xml nav_header.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"
          android:paddingBottom="@dimen/activity_vertical_margin"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"
          android:paddingTop="@dimen/activity_vertical_margin"
          android:theme="@style/ThemeOverlay.AppCompat.Dark"
          android:orientation="vertical"
          android:gravity="bottom">
</LinearLayout>

The names may change depending on the name of the activity. 名称可能会根据活动的名称而改变。

If you want an example, just leave a few days and you'll have. 如果您想举个例子,只需要离开几天,您就会拥有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM