【062】Android(安卓)开发入门学习
●·● 目录:
A1 ………… Android 目录简介
ANATOMY OF AN ANDROID APPLICATION
用"可视化"的方式来增加 String
AndroidManifest.xml 详解
A2 ………… Android 开发技巧
A3 ………… Android 创建工程
A4 ………… Android 控制台显示
A5 ………… Android 发短信实例
Android 目录简介:
- src:
xx.java: 程序的源文件. - gen:
R.java: 自动生成的, 不能随便修改. - assets:
里面的文件不在 R.java 中产生 id. - res:
里面的文件都会在 R.java 中生成一个唯一的 id, 可以通过 id 来访问文件.
drawable-xhdpi: 分辨率最高, 显示的图片最小, 但是看上去很清晰!
drawable-hdpi: 其次.
drawable-mdpi: 中间.
drawable-ldpi: 分辨率最小, 显示的图片最大, 但是看着不清楚.
放置图片的位置, 分为高中低等不同的图片分辨率.
将图片放在不同的文件夹, 分辨率会有不同!
layout:
xx.xml: 布局文件, 每个 Activity 都会对应一个布局文件.
values:
string.xml: 放置的是一些字段值, 用于软件的国际化.
<string-array>可以写入字符串数组. - AndroidManifest.xml:
对整个应用程序的一个配置, 包括 application, activity, 图标, 标签, 许可等.
在新建一个 activity 的时候, 一定要在该文件内部注册, 否则没办法显示, activity 中显示的标题要在此文件中定义.
下面内容参考:Beginning Android 4 Application Development Page30.
用"可视化"的方式来增加 String:
1> 点击 Add 按钮.
2> 在弹出的对话框中选择"String".
3> 在右边的 Name 和 Value 中分别加入相应的值, 直接填写, 不需要引号.
同理可以添加 Color, String Array, Activity, Permission, Uses Permission 等内容.
下面内容参考:Beginning Android 4 Application Development Page31.
Android 开发技巧:
- Android 模拟器竖横屏切换:Ctrl+F11
- 快速注释方法:Ctrl+/
- 重写/覆盖/提示:Alt+/
- 代码整体向右移动:Tab
- 代码整体向左移动:Shift+Tab
- 输入法中文:可以装个"百度输入法", 在输入框上长按会显示输入法, 选择即可!
- XML中的转义字符
- eclipse操作技巧(转)
- Ctrl+Shift+X:将选中的字母转成大写.
- Android开发效率—Eclipse快捷键
- 点击 Shift 键,同时双击文本,可以给文本加注释。
Android 建立工程:
新建文件:
Android Application Project:建立 Android 应用程序工程.
Android Project from Existing Code:从已有的 Android 应用程序工程的源代码来创建.
Android Sample Project:从 SDK 中自带的例子创建.
Android 控制台显示:
主菜单:Windows → Show View → Other... → LogCat, 如下显示:
点击左上角处的"+", 弹出如下的对话框, 同时输入想要监视的内容, 便可以监视 System.out
发短信功能实例:
Activity 布局:
代码部分:
layout/activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- 竖排的线性布局、宽度填充父窗体、高度填充父窗体 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/number" /><!-- 高度可以显示全部内容、显示的文本内容 --> <EditText android:id="@+id/number" android:layout_width="match_parent" android:layout_height="wrap_content" /><!-- 通过 R.id.number 可以查找 EditText --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/content" /> <EditText android:id="@+id/content" android:layout_width="match_parent" android:layout_height="wrap_content" android:minLines="3" /><!-- 显示的最小行数 --> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button" /></LinearLayout>
注意:xml 文件的注释要放在标签外面
src/MainActivity.java
package com.alexbnlee.sms;import java.util.ArrayList;import android.os.Bundle;import android.app.Activity;import android.telephony.SmsManager;import android.view.Menu;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class MainActivity extends Activity { private EditText numberText; //电话号码控件 private EditText contentText; //短信内容控件 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); numberText = (EditText)findViewById(R.id.number); //获取电话号码控件 contentText = (EditText)findViewById(R.id.content); //获取短信内容控件 Button button = (Button)findViewById(R.id.button); //获取按钮控件 button.setOnClickListener(new ButtonClickListener()); //设置按钮单击事件 } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } private final class ButtonClickListener implements View.OnClickListener{ public void onClick(View v) { // TODO Auto-generated method stub String number = numberText.getText().toString(); //获取电话号码文本 String content = contentText.getText().toString(); //获取短信内容文本 SmsManager manager = SmsManager.getDefault(); //发短信类 ArrayList<String> texts = manager.divideMessage(content); //短信过长的话,将短信分段处理发送 for(String text:texts){ manager.sendTextMessage(number, null, text, null, null); //遍历发送短信 } Toast.makeText(MainActivity.this, R.string.success, Toast.LENGTH_LONG).show(); //通过 Toast 通知“完成” } }}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.alexbnlee.sms" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <!-- 加入发短信许可 --> <uses-permission android:name="android.permission.SEND_SMS" /> </manifest>
更多相关文章
- Android(安卓)设置Activity窗体 不显示标题和全屏显示
- 【Android】Android布局文件的一些属性值
- Android(安卓)UI布局之区分 android:gravity 和 android:layout_
- android:paddingLeft 和 layout_marginLe 区别 android:layout_g
- android:layout_weight详解 (总结版)
- Android各控件常用属性
- XML Attributes(XML属性)
- Android(安卓)UI开发
- android EditText 自动滚动条并显示最新内容