Android studio 之 Menu(菜单)
一、菜单资源及选项菜单
首先,新建好项目后,删除layout文件夹及java的com.example.menutouch文件夹下所有文件
在layout文件夹下新建xml文件menu_layout.xml,使用线性布局LinearLayout,在线性布局里添加文本TextView和图片ImageView控件。
<?xml version="1.0" encoding="utf-8"?>
//第一行代码为固定代码,不可改变
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="30dp"
android:text="选项菜单测试" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@drawable/ic_launcher_background" />
</LinearLayout>
在AndroidManifest.xml文件中,需要手动添加一个最低和目标SDK版本为19。
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19">
</uses-sdk>
删除如下圈出的一行文字,这行文字是文件新建是自带的,表示不带的动作条。
利用