您的位置:首页 > 移动开发 > Android开发

【Android开发学习笔记】【第四课】基础控件的学习

2014-06-29 14:53 441 查看
  通过一个简单的例子来学习下面几种控件:

  1.TextView:简单的文本显示控件

  2.EditText:可以编辑的文本框

  3.Button:按钮

  4.Menu:这里指的是系统的Menu

  5.Toast:消息提示控件,类似于MFc的tip(不知道理解的对不对)

  顺便用到上一次学习的多个Activity之间传递数据的技术,来做一个小的计算乘法的case

  步骤:

  (1)主Activity 和显示结果的 Activity 都采用线性布局,下面是布局文件的源代码:  

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<EditText
android:id="@+id/MyEdit1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

<TextView
android:id="@+id/MyTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

<EditText
android:id="@+id/MyEdit2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

<Button
android:id="@+id/MyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</LinearLayout>


  上面是主Activity的布局

<?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="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/MyRes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</LinearLayout>


  上面是计算结果要用到的Activity

  (2)添加一个 计算结果处理 类 CalcActivity

    

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.controlview"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.controlview.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.controlview.CalcActivity"
android:label="calc" >
</activity>
</application>

</manifest>


AndroidManifest.xml
  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: