android Manifest.xml结构

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置为发送目的人,下边的为消息框里的汉字

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值