manifest的结构
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.mq.com.demo">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
1.写注意事项
activity包含在application里边
2.
<activity android:name=".MainActivity" android:label="@string/app_name">
android选项放在开始标记里
3.
一个xml的具体内容
<?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"
android:background="#000000">
<Button android:id="@+id/btnMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="打开主界面"
/>
<Button android:id="@+id/btnDial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拨号"
/>
<Button android:id="@+id/btnSMS"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="发短信"
/>
</LinearLayout>
1.对于某个插件,例如Button ,Textview
<Button android:id="@+id/btnDial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拨号"
/>
对Button和TextView的特点就像HTML语言那样,写在其开始的那个括号里,可以使用
package test.mq.com.demo;
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button btnMain,btnDial,btnSMS;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnMain=findViewById(R.id.btnMain);
btnDial=findViewById(R.id.btnDial);
btnSMS = findViewById(R.id.btnSMS);
btnMain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}
});
btnDial.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_DIAL);
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivity(intent);
}
});
btnSMS.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent();
intent.setData(Uri.parse("smsto:123456"));
intent.putExtra("sms_body","通过Android应用发送短消息");
startActivity(intent);
}
});
}
}
1.Intent就是将某个要处理的操作进行封装,用来在activy之间传递数据,例如上边的代码
intent.setAction(Intent.ACTION_DIAL);
intent.addCategory(Intent.CATEGORY_DEFAULT);
上边的代码省去了你编写拨打电话号码界面,直接使用已有的
传递数据
intent.setData(Uri.parse(“smsto:123456”));
intent.putExtra(“sms_body”,”通过Android应用发送短消息”);
这个就是打开了发短信界面,并且将123456置为发送目的人,下边的为消息框里的汉字