主要是练习布局——LinearLayout(线性布局)
AbsoluteLayout 绝对布局 TableLayout表格布局 FrameLayout布局
================ 拨号器 =====================
1、AndroidManifest.xml
------------------------------------------------------------------------------------------------------------
2、activity_main.xml
LinearLayout的android:orientation="vertical"必不可少......
<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" >
---------------------------------------------------------------------------------------------------------------
3、MainActivity.java
public class MainActivity extends Activity {
private EditText phone_num = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.dial_btn);
/*button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
phone_num = (EditText)findViewById(R.id.phone_num);
Intent intent = new Intent(Intent.ACTION_CALL,
Uri.parse("tel:"+phone_num.getText().toString()));
startActivity(intent);
//方法内部会自动为Intent添加类别:android.intent.category.DEFAULT
}
});*/
button.setOnClickListener(new ButtonOnClickListener());
}
/*@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}*/
public final class ButtonOnClickListener implements View.OnClickListener{
@Override
public void onClick(View v) {
phone_num = (EditText)findViewById(R.id.phone_num);
/*Intent intent = new Intent(Intent.ACTION_CALL,
Uri.parse("tel:"+phone_num.getText().toString())); **/
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+phone_num.getText().toString()));
startActivity(intent);
}
}
}
================ 短信发送器 =====================
/AndroidManifest.xml
android:label="@string/app_name" android:theme="@style/AppTheme" >
-----------------------------------------------------------------------------------------------
2、activity_main.xml
android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" >
android:layout_centerVertical="true"
android:layout_height="wrap_content" android:text="@string/phone_num" />
android:layout_height="wrap_content" android:id="@+id/phone_num"
android:layout_toRightOf="@id/numberlabel"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
/>
-------------------------------------------------------------------------------------
3、MainActivity.java
public class MainActivity extends Activity {
EditText phone_num = null;
EditText content = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.button);
phone_num = (EditText)findViewById(R.id.phone_num);
content = (EditText)findViewById(R.id.content);
button.setOnClickListener(new ButtonOnClickListener());
}
public final class ButtonOnClickListener implements View.OnClickListener{
@Override
public void onClick(View v) {
String mobile = phone_num.getText().toString();
String contentStr = content.getText().toString();
PendingIntent pendingIntent = PendingIntent
.getBroadcast(MainActivity.this, 0, new Intent(), 0);
SmsManager manager = SmsManager.getDefault();
ArrayList
for(String text : texts){
manager.sendTextMessage(mobile, null, text, pendingIntent, null);
}
Log.i("MainActivity", "mobile="+mobile+"; content="+contentStr);
Toast.makeText(MainActivity.this,R.string.success,Toast.LENGTH_LONG).show();
}
}