标签:android平台 java 短信 界面 字体
Activity的生命周期
Android的核心组件
1.Viiew :界面 ,组织UI控件
2.Intent :意图,支持组件之间的通信
3.Activity:处理界面与UI互动
4.Content Provider:存储共享数据
5.IntentReceiver:接收信息及时间处理
6.Service:后台服务(如硬件与驱动的服务 )
7.Notification:消息与通信
Android的运行
AndroidManifest.xml为程序的入口
R.文件是我们创建的一个目录文件
------------------------------------------------------------------
建立打电话发短信的应用程序
1.对number对话框定义
<EditText
android:id="@+id/NummberText" ----->在R文件中配置ID地址
android:layout_width="match_parent" ------>充满布局文件
android:layout_height="wrap_content"
android:layout_alignParentTop="true" ------>顶部对齐
android:layout_centerHorizontal="true" ----->居中
android:textColor="#FF0099" --------->设置文字的字体
android:ems="10"
android:hint="@string/SMS_please"
android:inputType="phone" > ------->默认的阴影提示
<requestFocus />
</EditText>
2.按钮的设计
<Button
android:id="@+id/Call_otherButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/NummberText" --->相对布局
android:textColor="#9900CC"------>设置文字的字体颜色
android:layout_centerHorizontal="true"
android:text="@string/call_other" />
<Button
android:id="@+id/Call_xiaoyuButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Call_otherButton"
android:textColor="#FF0033"
android:layout_centerHorizontal="true"
android:text="@string/love_xiaoyu" />
<Button
android:id="@+id/Call_mangqi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Call_xiaoyuButton"
android:layout_centerHorizontal="true"
android:text="@string/call_wangqi" />
3.设置小 layout
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Call_mangqi"
android:layout_below="@+id/Call_mangqi"
android:textColor="#FF9595"
android:text="@string/Talk_Message" />
------>@String在value文件中加载strings并在其中加载Talk_Message字符串
5.制作文本框
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:lines="8" --->设置函数的大小
android:hint="@string/_love" -->设计默认值得大小
android:ems="10"
android:inputType="textMultiLine" />
6逻辑设计
public class MainActivity extends Activity implements OnClickListener{
Button Call_other;
Button Call_wangqi;
Button Call_xiaoyu;
Button Send_other;
Button Send_wangqi;
Button Send_xiaoyu;
EditText Nummber_edit;
EditText Talk_Edit;
@Override
A-定义控件便于寻找
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Nummber_edit = (EditText)B-findViewById(R.id.NummberText); 通过findViewById来找到控制控件
Talk_Edit= (EditText)findViewById(R.id.editText1);
Call_other = (Button)findViewById(R.id.Call_otherButton);
Call_wangqi= (Button)findViewById(R.id.Call_mangqi);;
Call_xiaoyu= (Button)findViewById(R.id.Call_xiaoyuButton);;
Send_other= (Button)findViewById(R.id.Send_friend);
Send_wangqi= (Button)findViewById(R.id.Send_wangqi);
Send_xiaoyu= (Button)findViewById(R.id.Send_xiaoyu);
C -public class MainActivity extends Activity implements OnClickListener{
将主类实现OnClickListener接口可以对控件通过一个OnClick控制
D:1.在文件中设计按钮的事件
private void MyCallOther(){
String num = Nummber_edit.getText().toString();
if(TextUtils.isEmpty(num)){ ---判断字符中的文字是否为空
Toast.makeText(MainActivity.this, "电话为空了>.<", 0
--显示的时间).show();--土司生成
return ;
}else{
Intent intent = new Intent();----打电话的程序重要的一点事必须启动一个Intent的程序
Toast.makeText(MainActivity.this, "电话打向"+num, 0).show();--必须show出来
intent.setAction(Intent.ACTION_CALL);---设置打电话的设置
intent.setData(Uri.parse("tel:"+num));---设置电环号码
startActivity(intent);---启动事件
return;
}
}
private void MyCallxiaoyu(){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "Love晓宇691526", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"691526"));
startActivity(intent);
return ;
}
private void CallWangqi (){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "打给讨厌鬼王琪>.<", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"652008"));
startActivity(intent);
}
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:lines="8" --->设置函数的大小
android:hint="@string/_love" -->设计默认值得大小
android:ems="10"
android:inputType="textMultiLine" />
6逻辑设计
public class MainActivity extends Activity implements OnClickListener{
Button Call_other;
Button Call_wangqi;
Button Call_xiaoyu;
Button Send_other;
Button Send_wangqi;
Button Send_xiaoyu;
EditText Nummber_edit;
EditText Talk_Edit;
@Override
A-定义控件便于寻找
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Nummber_edit = (EditText)B-findViewById(R.id.NummberText); 通过findViewById来找到控制控件
Talk_Edit= (EditText)findViewById(R.id.editText1);
Call_other = (Button)findViewById(R.id.Call_otherButton);
Call_wangqi= (Button)findViewById(R.id.Call_mangqi);;
Call_xiaoyu= (Button)findViewById(R.id.Call_xiaoyuButton);;
Send_other= (Button)findViewById(R.id.Send_friend);
Send_wangqi= (Button)findViewById(R.id.Send_wangqi);
Send_xiaoyu= (Button)findViewById(R.id.Send_xiaoyu);
C -public class MainActivity extends Activity implements OnClickListener{
将主类实现OnClickListener接口可以对控件通过一个OnClick控制
D:1.在文件中设计按钮的事件
private void MyCallOther(){
String num = Nummber_edit.getText().toString();
if(TextUtils.isEmpty(num)){ ---判断字符中的文字是否为空
Toast.makeText(MainActivity.this, "电话为空了>.<", 0
--显示的时间).show();--土司生成
return ;
}else{
Intent intent = new Intent();----打电话的程序重要的一点事必须启动一个Intent的程序
Toast.makeText(MainActivity.this, "电话打向"+num, 0).show();--必须show出来
intent.setAction(Intent.ACTION_CALL);---设置打电话的设置
intent.setData(Uri.parse("tel:"+num));---设置电环号码
startActivity(intent);---启动事件
return;
}
}
private void MyCallxiaoyu(){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "Love晓宇691526", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"691526"));
startActivity(intent);
return ;
}
private void CallWangqi (){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "打给讨厌鬼王琪>.<", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"652008"));
startActivity(intent);
}
E:设置发短信的事件
private void SendFriend(){
String number = Nummber_edit.getText().toString();
String sms = Talk_Edit.getText().toString();
if(TextUtils.isEmpty(number)||TextUtils.isEmpty(sms)){---设置发短信的电话号码和控件
Toast.makeText(MainActivity.this, "信息为空了>.<", 0).show();
return ;
}else{
Toast.makeText(MainActivity.this, "信息发向了"+number, 0).show();
SmsManager message = SmsManager.getDefault();
message.sendTextMessage(number--电话,
null--发信者, sms--内容, null,null);---发短信
Toast.makeText(MainActivity.this, "信息发送成功>.<", 0).show();
}
}
private void SendWangqi(){
String sms = Talk_Edit.getText().toString();
Nummber_edit.setText("");
if(TextUtils.isEmpty(sms)){
Toast.makeText(MainActivity.this, "为空了>.<", 0).show();
return;
}
Toast.makeText(MainActivity.this, "信息发向了652008", 0).show();
SmsManager message = SmsManager.getDefault();
message.sendTextMessage("652008", null, sms, null, null);
Toast.makeText(MainActivity.this, "信息发送成功>.<", 0).show();
}
private void SendXiaoyu(){
String sms = Talk_Edit.getText().toString();
Nummber_edit.setText("");
if(TextUtils.isEmpty(sms)){
Toast.makeText(MainActivity.this, "为空了>.<", 0).show();
return;
}
Toast.makeText(MainActivity.this, "信息发向了691526", 0).show();
SmsManager message = SmsManager.getDefault();
message.sendTextMessage("691526", null, sms, null, null);
Toast.makeText(MainActivity.this, "信息发送成功>.<", 0).show();
}
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:lines="8" --->设置函数的大小
android:hint="@string/_love" -->设计默认值得大小
android:ems="10"
android:inputType="textMultiLine" />
6逻辑设计
public class MainActivity extends Activity implements OnClickListener{
Button Call_other;
Button Call_wangqi;
Button Call_xiaoyu;
Button Send_other;
Button Send_wangqi;
Button Send_xiaoyu;
EditText Nummber_edit;
EditText Talk_Edit;
@Override
A-定义控件便于寻找
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Nummber_edit = (EditText)B-findViewById(R.id.NummberText); 通过findViewById来找到控制控件
Talk_Edit= (EditText)findViewById(R.id.editText1);
Call_other = (Button)findViewById(R.id.Call_otherButton);
Call_wangqi= (Button)findViewById(R.id.Call_mangqi);;
Call_xiaoyu= (Button)findViewById(R.id.Call_xiaoyuButton);;
Send_other= (Button)findViewById(R.id.Send_friend);
Send_wangqi= (Button)findViewById(R.id.Send_wangqi);
Send_xiaoyu= (Button)findViewById(R.id.Send_xiaoyu);
C -public class MainActivity extends Activity implements OnClickListener{
将主类实现OnClickListener接口可以对控件通过一个OnClick控制
D:1.在文件中设计按钮的事件
private void MyCallOther(){
String num = Nummber_edit.getText().toString();
if(TextUtils.isEmpty(num)){ ---判断字符中的文字是否为空
Toast.makeText(MainActivity.this, "电话为空了>.<", 0
--显示的时间).show();--土司生成
return ;
}else{
Intent intent = new Intent();----打电话的程序重要的一点事必须启动一个Intent的程序
Toast.makeText(MainActivity.this, "电话打向"+num, 0).show();--必须show出来
intent.setAction(Intent.ACTION_CALL);---设置打电话的设置
intent.setData(Uri.parse("tel:"+num));---设置电环号码
startActivity(intent);---启动事件
return;
}
}
private void MyCallxiaoyu(){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "Love晓宇691526", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"691526"));
startActivity(intent);
return ;
}
private void CallWangqi (){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "打给讨厌鬼王琪>.<", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"652008"));
startActivity(intent);
}
7.定义单击清空设置
private void ClearEdi(){
Nummber_edit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Nummber_edit.setText("");
}
});
Talk_Edit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Talk_Edit.setText("");
}
});
8>添加系统的单机事件
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.Call_otherButton : --通过R地址寻找控件
MyCallOther();ClearEdi(); 执行对应的方法
break;
case R.id.Call_xiaoyuButton :
MyCallxiaoyu();
break;
case R.id.Call_mangqi:
CallWangqi ();ClearEdi();
break;
case R.id.Send_friend:
SendFriend();ClearEdi();
break;
case R.id.Send_wangqi:
SendWangqi();ClearEdi();
break;
case R.id.Send_xiaoyu:
SendXiaoyu();ClearEdi();
break;
default:
// ClearEdi();
}
}
9:添加权限
----------------------------------------------------------------------
原码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="@+id/NummberText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textColor="#FF0099"
android:ems="10"
android:hint="@string/SMS_please"
android:inputType="phone" >
<requestFocus />
</EditText>
<Button
android:id="@+id/Call_otherButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/NummberText"
android:textColor="#9900CC"
android:layout_centerHorizontal="true"
android:text="@string/call_other" />
<Button
android:id="@+id/Call_xiaoyuButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Call_otherButton"
android:textColor="#FF0033"
android:layout_centerHorizontal="true"
android:text="@string/love_xiaoyu" />
<Button
android:id="@+id/Call_mangqi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Call_xiaoyuButton"
android:layout_centerHorizontal="true"
android:text="@string/call_wangqi" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Call_mangqi"
android:layout_below="@+id/Call_mangqi"
android:textColor="#FF9595"
android:text="@string/Talk_Message" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:lines="8"
android:hint="@string/_love"
android:ems="10"
android:inputType="textMultiLine" />
<Button
android:id="@+id/Send_wangqi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginLeft="29dp"
android:textColor="#0033FF"
android:text="@string/send_wangqi" />
<Button
android:id="@+id/Send_xiaoyu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginRight="25dp"
android:textColor="#FF00CC"
android:text="@string/send_xiaoyu" />
<Button
android:id="@+id/Send_friend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Send_wangqi"
android:layout_centerHorizontal="true"
android:textColor="#9933FF"
android:layout_marginTop="20dp"
android:text="Send_friend" />
</RelativeLayout>
-----
package com.example.love_happy;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Telephony.Sms;
import android.app.Activity;
import android.content.Intent;
import android.telephony.gsm.SmsManager;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
Button Call_other;
Button Call_wangqi;
Button Call_xiaoyu;
Button Send_other;
Button Send_wangqi;
Button Send_xiaoyu;
EditText Nummber_edit;
EditText Talk_Edit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Nummber_edit = (EditText)findViewById(R.id.NummberText);
Talk_Edit= (EditText)findViewById(R.id.editText1);
Call_other = (Button)findViewById(R.id.Call_otherButton);
Call_wangqi= (Button)findViewById(R.id.Call_mangqi);;
Call_xiaoyu= (Button)findViewById(R.id.Call_xiaoyuButton);;
Send_other= (Button)findViewById(R.id.Send_friend);
Send_wangqi= (Button)findViewById(R.id.Send_wangqi);
Send_xiaoyu= (Button)findViewById(R.id.Send_xiaoyu);
Call_other.setOnClickListener(MainActivity.this);
Call_wangqi.setOnClickListener(MainActivity.this);
Call_xiaoyu.setOnClickListener(MainActivity.this);
Send_other.setOnClickListener(MainActivity.this);
Send_wangqi.setOnClickListener(MainActivity.this);
Send_xiaoyu.setOnClickListener(MainActivity.this);
Nummber_edit.setOnClickListener(MainActivity.this);
Talk_Edit.setOnClickListener(MainActivity.this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void MyCallOther(){
String num = Nummber_edit.getText().toString();
if(TextUtils.isEmpty(num)){
Toast.makeText(MainActivity.this, "电话为空了>.<", 0).show();
return ;
}else{
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "电话打向"+num, 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+num));
startActivity(intent);
return;
}
}
private void MyCallxiaoyu(){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "Love晓宇691526", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"691526"));
startActivity(intent);
return ;
}
private void CallWangqi (){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "打给讨厌鬼王琪>.<", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"652008"));
startActivity(intent);
}
private void SendFriend(){
String number = Nummber_edit.getText().toString();
String sms = Talk_Edit.getText().toString();
if(TextUtils.isEmpty(number)||TextUtils.isEmpty(sms)){
Toast.makeText(MainActivity.this, "信息为空了>.<", 0).show();
return ;
}else{
Toast.makeText(MainActivity.this, "信息发向了"+number, 0).show();
SmsManager message = SmsManager.getDefault();
message.sendTextMessage(number, null, sms, null,null);
Toast.makeText(MainActivity.this, "信息发送成功>.<", 0).show();
}
}
private void SendWangqi(){
String sms = Talk_Edit.getText().toString();
Nummber_edit.setText("");
if(TextUtils.isEmpty(sms)){
Toast.makeText(MainActivity.this, "为空了>.<", 0).show();
return;
}
Toast.makeText(MainActivity.this, "信息发向了652008", 0).show();
SmsManager message = SmsManager.getDefault();
message.sendTextMessage("652008", null, sms, null, null);
Toast.makeText(MainActivity.this, "信息发送成功>.<", 0).show();
}
private void SendXiaoyu(){
String sms = Talk_Edit.getText().toString();
Nummber_edit.setText("");
if(TextUtils.isEmpty(sms)){
Toast.makeText(MainActivity.this, "为空了>.<", 0).show();
return;
}
Toast.makeText(MainActivity.this, "信息发向了691526", 0).show();
SmsManager message = SmsManager.getDefault();
message.sendTextMessage("691526", null, sms, null, null);
Toast.makeText(MainActivity.this, "信息发送成功>.<", 0).show();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.Call_otherButton :
MyCallOther();ClearEdi();
break;
case R.id.Call_xiaoyuButton :
MyCallxiaoyu();
break;
case R.id.Call_mangqi:
CallWangqi ();ClearEdi();
break;
case R.id.Send_friend:
SendFriend();ClearEdi();
break;
case R.id.Send_wangqi:
SendWangqi();ClearEdi();
break;
case R.id.Send_xiaoyu:
SendXiaoyu();ClearEdi();
break;
default:
// ClearEdi();
}
}
private void ClearEdi(){
Nummber_edit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Nummber_edit.setText("");
}
});
Talk_Edit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Talk_Edit.setText("");
}
});
}
}
----
Sting:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Love_晓宇</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="SMS_please">请输入电话号码或收信人</string>
<string name="call_other">Call_Other</string>
<string name="love_xiaoyu">Love_晓宇</string>
<string name="call_王琪">Call_wangqi</string>
<string name="call_wangqi">Call_王琪>.</string>
<string name="Talk_Message">风声细语</string>
<string name="send_wangqi">Send_王琪</string>
<string name="send_xiaoyu">Send_晓宇</string>
<string name="_love">希望你开心..</string>
</resources>
----
R
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.example.love_happy;
public final class R {
public static final class attr {
}
public static final class dimen {
/** Default screen margins, per the Android Design guidelines.
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
*/
public static final int activity_horizontal_margin=0x7f040000;
public static final int activity_vertical_margin=0x7f040001;
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int Call_mangqi=0x7f080003;
public static final int Call_otherButton=0x7f080001;
public static final int Call_xiaoyuButton=0x7f080002;
public static final int NummberText=0x7f080000;
public static final int Send_friend=0x7f080008;
public static final int Send_wangqi=0x7f080006;
public static final int Send_xiaoyu=0x7f080007;
public static final int action_settings=0x7f080009;
public static final int editText1=0x7f080005;
public static final int textView1=0x7f080004;
}
public static final class layout {
public static final int activity_main=0x7f030000;
}
public static final class menu {
public static final int main=0x7f070000;
}
public static final class string {
public static final int SMS_please=0x7f050003;
public static final int Talk_Message=0x7f050008;
public static final int _love=0x7f05000b;
public static final int action_settings=0x7f050001;
public static final int app_name=0x7f050000;
public static final int call_other=0x7f050004;
public static final int call_wangqi=0x7f050007;
public static final int call_鐜嬬惇=0x7f050006;
public static final int hello_world=0x7f050002;
public static final int love_xiaoyu=0x7f050005;
public static final int send_wangqi=0x7f050009;
public static final int send_xiaoyu=0x7f05000a;
}
public static final class style {
/**
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
API 11 theme customizations can go here.
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
API 14 theme customizations can go here.
*/
public static final int AppBaseTheme=0x7f060000;
/** Application theme.
All customizations that are NOT specific to a particular API-level can go here.
*/
public static final int AppTheme=0x7f060001;
}
}
----
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:lines="8" --->设置函数的大小
android:hint="@string/_love" -->设计默认值得大小
android:ems="10"
android:inputType="textMultiLine" />
6逻辑设计
public class MainActivity extends Activity implements OnClickListener{
Button Call_other;
Button Call_wangqi;
Button Call_xiaoyu;
Button Send_other;
Button Send_wangqi;
Button Send_xiaoyu;
EditText Nummber_edit;
EditText Talk_Edit;
@Override
A-定义控件便于寻找
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Nummber_edit = (EditText)B-findViewById(R.id.NummberText); 通过findViewById来找到控制控件
Talk_Edit= (EditText)findViewById(R.id.editText1);
Call_other = (Button)findViewById(R.id.Call_otherButton);
Call_wangqi= (Button)findViewById(R.id.Call_mangqi);;
Call_xiaoyu= (Button)findViewById(R.id.Call_xiaoyuButton);;
Send_other= (Button)findViewById(R.id.Send_friend);
Send_wangqi= (Button)findViewById(R.id.Send_wangqi);
Send_xiaoyu= (Button)findViewById(R.id.Send_xiaoyu);
C -public class MainActivity extends Activity implements OnClickListener{
将主类实现OnClickListener接口可以对控件通过一个OnClick控制
D:1.在文件中设计按钮的事件
private void MyCallOther(){
String num = Nummber_edit.getText().toString();
if(TextUtils.isEmpty(num)){ ---判断字符中的文字是否为空
Toast.makeText(MainActivity.this, "电话为空了>.<", 0
--显示的时间).show();--土司生成
return ;
}else{
Intent intent = new Intent();----打电话的程序重要的一点事必须启动一个Intent的程序
Toast.makeText(MainActivity.this, "电话打向"+num, 0).show();--必须show出来
intent.setAction(Intent.ACTION_CALL);---设置打电话的设置
intent.setData(Uri.parse("tel:"+num));---设置电环号码
startActivity(intent);---启动事件
return;
}
}
private void MyCallxiaoyu(){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "Love晓宇691526", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"691526"));
startActivity(intent);
return ;
}
private void CallWangqi (){
Intent intent = new Intent();
Toast.makeText(MainActivity.this, "打给讨厌鬼王琪>.<", 0).show();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"652008"));
startActivity(intent);
}
7.定义单击清空设置
private void ClearEdi(){
Nummber_edit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Nummber_edit.setText("");
}
});
Talk_Edit.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Talk_Edit.setText("");
}
});
8>添加系统的单机事件
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.Call_otherButton : --通过R地址寻找控件
MyCallOther();ClearEdi(); 执行对应的方法
break;
case R.id.Call_xiaoyuButton :
MyCallxiaoyu();
break;
case R.id.Call_mangqi:
CallWangqi ();ClearEdi();
break;
case R.id.Send_friend:
SendFriend();ClearEdi();
break;
case R.id.Send_wangqi:
SendWangqi();ClearEdi();
break;
case R.id.Send_xiaoyu:
SendXiaoyu();ClearEdi();
break;
default:
// ClearEdi();
}
}
老师我在学校建立了一个群想让我们这里的高手加入点击链接加入群
【电子软件】:http://jq.qq.com/?_wv=1027&k=SnEvzz
是大学生传奇工作室的学习交流群,该群是单片机应用,C,java,C++Android..上位机的学习交流群,学习涉及三大类1.机械原理Proe,Inventer三维建模,机械制造 2.单片机,电子电路,PLC底层应用 2. C++逻辑算法,java Android 的软件开发的学生团队
群名称是电子软件 280547133
280547133280547133280547133
Android-2电话应用,短信应用
标签:android平台 java 短信 界面 字体
原文地址:http://blog.csdn.net/u012651389/article/details/40600653