package com.example.administrator.helloworld;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
public class helloworld extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_helloworld);
if (checkSelfPermission(Manifest.permission.CALL_PHONE) == PERMISSION_DENIED) {
requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, 0x11);
}
((Button) findViewById(R.id.button2)).setOnClickListener(new buttonClickListener());
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case 0x11:
break;
default:
break;
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
private class buttonClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
EditText textView = findViewById(R.id.editText2);
String strNumber = textView.getText().toString().trim();
if (strNumber.isEmpty()) {
Toast.makeText(helloworld.this, "电话号码不能为空", Toast.LENGTH_LONG).show();
return;
}
if (checkSelfPermission(Manifest.permission.CALL_PHONE) == PERMISSION_DENIED) {
requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, 0x11);
return;
}
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + strNumber));
startActivity(intent);
}
}
}
((Button) findViewById(R.id.button2)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
public class helloworld extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_helloworld);
if (checkSelfPermission(Manifest.permission.CALL_PHONE) == PERMISSION_DENIED) {
requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, 0x11);
}
((Button) findViewById(R.id.button2)).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button2:
break;
}
}
在代码中添加该方法
public class helloworld extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_helloworld);
if (checkSelfPermission(Manifest.permission.CALL_PHONE) == PERMISSION_DENIED) {
requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, 0x11);
}
((Button) findViewById(R.id.button2)).setOnClickListener(this);
}
public void selfDefine(View v) {
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
LinearLayout>
给item添加margin
"1.0" encoding="utf-8"?>
"http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
"@+id/tv_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="请输入电话号码"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入电话号码0"/>
<TextView
android:id="@+id/tv_number1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入电话号码1"
android:layout_below="@id/tv_number"/>
<TextView
android:id="@+id/tv_number2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入电话号码2"
android:layout_below="@id/tv_number1"/>
<TextView
android:id="@+id/tv_number3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入电话号码3"
android:layout_toRightOf="@id/tv_number2"
android:layout_below="@id/tv_number1"/>
RelativeLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="哈哈哈"
android:layout_gravity="center"/>
<EditText
android:id="@+id/et_input"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="请输入电话号码" />
FrameLayout>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="哈哈哈"
android:textColor="#ff0000"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="hehe"
android:textColor="#00ff00"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="ssssss"
android:textColor="#ffff00"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="aaaaaa"
android:textColor="#100ff0"
android:textSize="18sp"/>
TableRow>
TableLayout>
绝对布局(已废弃)
约束布局
https://www.jianshu.com/p/a74557359882
sp 一般用来给文字设置大小
dp 用来设置控件的位置,宽度和高度