您的位置:首页 > 其它

制作手机短信发送助手

2016-09-04 19:46 435 查看
制作布局界面

一个简单的手机助手需要三个界面

第一个是短信发送的主界面

其次是短信助手的显示界面

最后是TextView的界面

<LinearLayout 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:orientation="vertical"

tools:context=".MainActivity" >

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="center_horizontal"

android:text="短信助手"

android:textColor="#ff0000"

android:textSize="28sp" />

<Button

android:onClick="selectSms"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="选择短信"

/>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@+id/tv_content"

android:text="短信内容"

android:textColor="#00ff00"

android:textSize="22sp" />

</LinearLayout>

第二个的代码为

<?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" >

<ListView

android:id="@+id/lv"

android:layout_width="match_parent"

android:layout_height="match_parent" >

</ListView>

</LinearLayout>

第三个代码为

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:text="haha"

android:textColor="#0000ff"

android:textSize="20sp"

android:layout_height="wrap_content" >

</TextView>

之后在mianAcctivity中填写代码

public class MainActivity
extends Activity {

private TextView
tv_content;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

tv_content = (TextView) findViewById(R.id.tv_content);

}

Public void fasong (View view ){

Intent intent (this,SecondActivity));

startActivityForResult(intent ,0);

}

protected void onActivityResult(int requestCode,
int resultCode, Intent data) {

If(data!=null){

String text = data.getStringExtra(“text”);

Tv_context.settext(text);

}

else{

tv_context.settext(“没有duanxin”);

}

super.onActivityResult(requestCode, resultCode, data);

}

之后在src中建立一个新的class
把他命名为SelectSMSActivity.java

Public void SelectSMSActivity extends Activity{

private TextView
tv;

private String[]
smscontents={"羊年大吉","羊年happy","哈哈哈
,新年快乐","新春快乐","天天发财","彩票中奖","^_^"};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

lv = (ListView) findViewById(R.id.lv);

setContentView(R.layout.activity_select_sms);

lv.setAdapter(newArrayAdapter<String>(this, R.layout.item_textview,
smscontents));

}

制作布局界面

一个简单的手机助手需要三个界面

第一个是短信发送的主界面

其次是短信助手的显示界面

最后是TextView的界面

<LinearLayout 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:orientation="vertical"

tools:context=".MainActivity" >

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="center_horizontal"

android:text="短信助手"

android:textColor="#ff0000"

android:textSize="28sp" />

<Button

android:onClick="selectSms"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="选择短信"

/>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@+id/tv_content"

android:text="短信内容"

android:textColor="#00ff00"

android:textSize="22sp" />

</LinearLayout>

第二个的代码为

<?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" >

<ListView

android:id="@+id/lv"

android:layout_width="match_parent"

android:layout_height="match_parent" >

</ListView>

</LinearLayout>

第三个代码为

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:text="haha"

android:textColor="#0000ff"

android:textSize="20sp"

android:layout_height="wrap_content" >

</TextView>

之后在mianAcctivity中填写代码

public class MainActivity
extends Activity {

private TextView
tv_content;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

tv_content = (TextView) findViewById(R.id.tv_content);

}

Public void fasong (View view ){

Intent intent (this,SecondActivity));

startActivityForResult(intent ,0);

}

protected void onActivityResult(int requestCode,
int resultCode, Intent data) {

If(data!=null){

String text = data.getStringExtra(“text”);

Tv_context.settext(text);

}

else{

tv_context.settext(“没有duanxin”);

}

super.onActivityResult(requestCode, resultCode, data);

}

之后在src中建立一个新的class
把他命名为SelectSMSActivity.java

Public void SelectSMSActivity extends Activity{

private TextView
tv;

private String[]
smscontents={"羊年大吉","羊年happy","哈哈哈
,新年快乐","新春快乐","天天发财","彩票中奖","^_^"};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

lv = (ListView) findViewById(R.id.lv);

setContentView(R.layout.activity_select_sms);

lv.setAdapter(newArrayAdapter<String>(this, R.layout.item_textview,
smscontents));

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