鱼C论坛

 找回密码
 立即注册
查看: 2650|回复: 0

[学习笔记] android手机编程2.3

[复制链接]
发表于 2017-9-17 10:31:30 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 alltolove 于 2017-9-17 10:34 编辑

首先在activity_second.xml里添加个按钮
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:orientation="vertical"
  5.     android:layout_height="match_parent"
  6.     android:layout_width="match_parent">
  7.     <Button
  8.         android:layout_width="match_parent"
  9.         android:layout_height="wrap_content"
  10.         android:text="@string/button_name"
  11.         android:id="@+id/btn"/>
  12.     <Button
  13.         android:layout_width="match_parent"
  14.         android:layout_height="wrap_content"
  15.         android:text="dial"
  16.         android:id="@+id/btn1"/>
  17. </LinearLayout>
复制代码

然后在androidmanifest.xml文件下manifest标签里添加一个授权
  1. <uses-permission android:name="android.permission.CALL_PHONE" ></uses-permission>
复制代码

将secondactivity.java修改为:
  1. package com.example.xinwei.test;

  2. import android.content.Intent;
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;

  7. public class SecondActivity extends AppCompatActivity {

  8.     @Override
  9.     protected void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);
  11.         setContentView(R.layout.activity_second);
  12.         Button btn =(Button)findViewById(R.id.btn);
  13.         btn.setOnClickListener(new View.OnClickListener() {
  14.             @Override
  15.             public void onClick(View view) {
  16.                 finish();
  17.             }
  18.         });
  19.         Button btn1 = (Button)findViewById(R.id.btn1);
  20.         btn1.setOnClickListener(new View.OnClickListener() {
  21.             @Override
  22.             public void onClick(View view) {
  23.                 Intent intent = new Intent();
  24.                 intent.setAction(Intent.ACTION_DIAL);
  25.                 startActivity(intent);
  26.             }
  27.         });
  28.     }
  29. }
复制代码

效果图:
jdfw.gif

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-26 12:15

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表