学习Android Studio开发工具之Activity3(框架1)

这篇博客详细介绍了在Android Studio中创建Navigation Drawer Activity的步骤。通过新建一个名为'framwork'的Module,作者展示了如何生成带有侧滑栏的效果,并讲解了相关布局文件如ic_menu_camera.xml、side_nav_bar.xml、nav_header_main.xml、content_main.xml、app_bar_main.xml、activity_main.xml之间的关系。此外,还提及了侧滑导航菜单activity_main_drawer.xml和关键的MainActivity.java文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在新建一个Module的时候总是经过这样一个activity类型的选择:
这里写图片描述
我们新建的Module名为framwork,选择Navigation Drawer Activity
完成后的效果如图:
这里写图片描述
其中举一个例子显示图标的绘制过程,在drawer-v12文件夹下打开ic_menu_camera.xml,如图:
这里写图片描述

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportHeight="24.0"
        android:viewportWidth="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
    <path
        android:fillColor="#FF000000"
        android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
</vector>

背景文件 drawable/side_nav_bar.xml
这里写图片描述

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <gradient
        android:angle="135"
        android:centerColor="#4CAF50"
        android:endColor="#2E7D32"
        android:startColor="#81C784"
        android:type="linear"/>
</shape>

侧滑栏布局文件nav_header_main.xml
这里写图片描述

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="@dimen/nav_header_height"
              android:background="@drawable/side_nav_bar"
              android:gravity="bottom"
              android:orientation="vertical"
              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">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值