电话文本android(3)_拨打电话操作
发一下牢骚和主题无关:
拨打电话项目:
activity_phone.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".PhoneActivity" > <!-- android:id:id 布局:wrap_content包裹 android:layout_width:宽 android:layout_height:高 text: 显示的文本引用 android:layout_below:在什么下方 --> <TextView android:id="@+id/viewphone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/phone" /> <EditText android:id="@+id/editphone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/viewphone" android:layout_below="@+id/viewphone" android:layout_marginTop="16dp" android:ems="10" android:inputType="phone" > <requestFocus /> </EditText> <Button android:id="@+id/btnphone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editphone" android:layout_below="@+id/editphone" android:layout_marginTop="23dp" android:text="@string/buttonphone" /> </RelativeLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">lession01_phone</string> <string name="action_settings">Settings</string> <string name="phone">拨打电话</string> <string name="buttonphone">拨打</string> </resources>
添加权限
PhoneActivity.java
package com.example.lession01_phone; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class PhoneActivity extends Activity { private Button button_phone; private EditText edit_phone; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_phone); button_phone = (Button) findViewById(R.id.btnphone); edit_phone = (EditText)findViewById(R.id.editphone); button_phone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String phone_Num = edit_phone.getText().toString(); Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phone_Num)); PhoneActivity.this.startActivity(intent); Toast.makeText(PhoneActivity.this, "正在给"+phone_Num+"拨打",Toast.LENGTH_LONG).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.phone, menu); return true; } }
运行效果:
文章结束给大家分享下程序员的一些笑话语录:
人在天涯钻,哪儿能不挨砖?日啖板砖三百颗,不辞长做天涯人~
---------------------------------
原创文章 By
电话和文本
---------------------------------