1、创建android项目
2、构建layout页面
基于相对的RelativeLayout
主要实现代码
android:id="@+id/XX"定义id地址
控件的宽度和高度
android:layout_width="wrap_content"
android:layout_height="wrap_content"
控件与母板居中显示
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
整个布局距离左边和上部的距离
android:layout_marginLeft="100dp"
android:layout_marginTop="40dp"
显示控件内容,与values-〉strings-〉name对应
android:text="@string/tipInfo" />
<TextView
android:id="@+id/tipPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="100dp"
android:layout_marginTop="40dp"
android:text="@string/tipInfo" />
<EditText
android:id="@+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tipPhone"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:ems="10"
android:inputType="phone" >
<requestFocus />
</EditText>
<Button
android:id="@+id/callPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/etPhone"
android:text="@string/callBtn" >
</Button>
3、创建activity事件
定位到控件id
findViewById(R.id.etPhone);
监听拨号按钮
callBtn.setOnClickListener()
将输入的号码传入
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phoneNum));
启动事件
PhoneActivity.this.startActivity(intent);
final EditText editText = (EditText) findViewById(R.id.etPhone);
Button callBtn = (Button) findViewById(R.id.callPhone);
callBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String phoneNum = editText.getText().toString();
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phoneNum));
PhoneActivity.this.startActivity(intent);
}
});
4、替换图标
使用png图标、
android:icon="@drawable/xx"
5、启动事件的拦截
从phoneActivity启动事件
<activity
android:name="ww.csdn.net.lesson01.PhoneActivity"
android:label="@string/title_activity_phone" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
总结:
JVM与DVM的区别
区别一:dvm执行的是.dex格式文件 jvm执行的是.class文件 android程序编译完之后生产.class文件,然后,dex工具会把.class文件处理成.dex文件,然后把资源文件和.dex文件等打包成.apk文件。apk就是android package的意思。 jvm执行的是.class文件。
区别二:dvm是基于寄存器的虚拟机 而jvm执行是基于虚拟栈的虚拟机。寄存器存取速度比栈快的多,dvm可以根据硬件实现最大的优化,比较适合移动设备。
区别三:.class文件存在很多的冗余信息,dex工具会去除冗余信息,并把所有的.class文件整合到.dex文件中。减少了I/O操作,提高了类的查找速度