标签:
1.AndroidManifest.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example.administrator.lx"> 4 5 <application 6 android:allowBackup="true" 7 android:icon="@mipmap/ic_launcher" 8 android:label="@string/app_name" 9 android:supportsRtl="true" 10 android:theme="@style/AppTheme"> 11 <activity android:name=".MainActivity"> 12 <intent-filter> 13 <action android:name="android.intent.action.MAIN" /> 14 15 <category android:name="android.intent.category.LAUNCHER" /> 16 </intent-filter> 17 </activity> 18 </application> 19 20 </manifest>
2.ManiActivity.java
1 package com.example.administrator.lx; 2 3 import android.app.AlertDialog; 4 import android.content.DialogInterface; 5 import android.content.Intent; 6 import android.net.Uri; 7 import android.support.v7.app.AppCompatActivity; 8 import android.os.Bundle; 9 import android.view.LayoutInflater; 10 import android.view.View; 11 import android.widget.Toast; 12 13 import java.net.URI; 14 15 public class MainActivity extends AppCompatActivity { 16 17 @Override 18 protected void onCreate(Bundle savedInstanceState) { 19 super.onCreate(savedInstanceState); 20 setContentView(R.layout.activity_main); 21 } 22 23 public void suiji(View v) 24 { 25 LayoutInflater layoutInflater = getLayoutInflater(); 26 View view = layoutInflater.inflate(R.layout.suiji,null); 27 new AlertDialog.Builder(this) 28 .setTitle("随机数") 29 .setView(view) 30 .show(); 31 } 32 public void duihua(View v) 33 { 34 AlertDialog alertDialog = new AlertDialog.Builder(this) 35 .setTitle("提示") 36 .setMessage("你确定要删除吗?") 37 .setNegativeButton("取消", new DialogInterface.OnClickListener() { 38 @Override 39 public void onClick(DialogInterface dialog, int which) { 40 Toast.makeText(MainActivity.this, "取消删除……", Toast.LENGTH_SHORT).show(); 41 } 42 }) 43 .setPositiveButton("确定", new DialogInterface.OnClickListener() { 44 @Override 45 public void onClick(DialogInterface dialog, int which) { 46 Toast.makeText(MainActivity.this, "确定删除……", Toast.LENGTH_SHORT).show(); 47 } 48 }) 49 .setCancelable(false) 50 .show(); 51 } 52 public void phone(View v) 53 { 54 LayoutInflater layoutInflater = getLayoutInflater(); 55 View view = layoutInflater.inflate(R.layout.phone, null); 56 57 new AlertDialog.Builder(this) 58 59 .setTitle("phone") 60 .setView(view) 61 .setCancelable(false) 62 .show(); 63 64 Intent intent = new Intent(Intent.ACTION_CALL); 65 66 Uri uri = Uri.parse(""); 67 68 intent.setData(uri); 69 70 try { 71 startActivity(intent); 72 } 73 catch (Exception e) 74 { 75 e.printStackTrace(); 76 } 77 } 78 }
3.activity_mani.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:paddingBottom="@dimen/activity_vertical_margin" 7 android:paddingLeft="@dimen/activity_horizontal_margin" 8 android:paddingRight="@dimen/activity_horizontal_margin" 9 android:paddingTop="@dimen/activity_vertical_margin" 10 tools:context="com.example.administrator.lx.MainActivity" 11 android:orientation="vertical"> 12 13 <Button 14 android:layout_width="match_parent" 15 android:layout_height="wrap_content" 16 android:text="随机数" 17 android:onClick="suiji"/> 18 <Button 19 android:layout_width="match_parent" 20 android:layout_height="wrap_content" 21 android:text="对话框" 22 android:onClick="duihua"/> 23 <Button 24 android:layout_width="match_parent" 25 android:layout_height="wrap_content" 26 android:text="电话短信" 27 android:onClick="phone"/> 28 </LinearLayout>
4.suiji.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 <TextView 6 android:layout_width="match_parent" 7 android:layout_height="wrap_content" 8 android:text="请点击按钮生成随机数" 9 android:textSize="20dp"/> 10 <EditText 11 android:layout_width="match_parent" 12 android:layout_height="wrap_content" 13 /> 14 <Button 15 android:layout_width="match_parent" 16 android:layout_height="wrap_content" 17 android:text="单击生成" 18 android:id="@+id/suiji" 19 /> 20 </LinearLayout>
5.phone.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 <EditText 6 android:layout_width="match_parent" 7 android:layout_height="wrap_content" 8 android:hint="请输入电话号码" 9 android:id="@+id/text"/> 10 <Button 11 android:layout_width="match_parent" 12 android:layout_height="wrap_content" 13 android:text="拨打电话" 14 android:id="@+id/phone" 15 android:onClick="ding"/> 16 <Button 17 android:layout_width="match_parent" 18 android:layout_height="wrap_content" 19 android:text="发送短信" 20 android:id="@+id/sms" 21 android:onClick="dang"/> 22 </LinearLayout>
标签:
原文地址:http://www.cnblogs.com/TENOKAWA/p/5492160.html