android手机编程2.3
本帖最后由 alltolove 于 2017-9-17 10:34 编辑首先在activity_second.xml里添加个按钮<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/button_name"
android:id="@+id/btn"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dial"
android:id="@+id/btn1"/>
</LinearLayout>
然后在androidmanifest.xml文件下manifest标签里添加一个授权<uses-permission android:name="android.permission.CALL_PHONE" ></uses-permission>
将secondactivity.java修改为:
package com.example.xinwei.test;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class SecondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Button btn =(Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
Button btn1 = (Button)findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_DIAL);
startActivity(intent);
}
});
}
}
效果图:
页:
[1]