Dialing project:
Activity_phone.xml
[Html]
<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
Layout: wrap_content package
Android: layout_width: width
Android: layout_height: high
Text: displays text references.
Android: layout_below: Under what
-->
<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>
<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
Layout: wrap_content package
Android: layout_width: width
Android: layout_height: high
Text: displays text references.
Android: layout_below: Under what
-->
<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
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "app_name"> lession01_phone </string>
<String name = "action_settings"> Settings </string>
<String name = "phone"> call </string>
<String name = "buttonphone"> call </string>
</Resources>
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "app_name"> lession01_phone </string>
<String name = "action_settings"> Settings </string>
<String name = "phone"> call </string>
<String name = "buttonphone"> call </string>
</Resources>
Add permission
PhoneActivity. java
[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, "is giving" + phone_Num + "dial", 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;
}
}
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, "is giving" + phone_Num + "dial", 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;
}
}
Running effect: