温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android中怎么实现一个电话拨号器

发布时间:2021-06-26 16:43:59 来源:亿速云 阅读:188 作者:Leah 栏目:移动开发

本篇文章给大家分享的是有关Android中怎么实现一个电话拨号器,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

package com.example.phone; 
 
import android.support.v7.app.ActionBarActivity; 
import android.support.v4.app.Fragment; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup; 
import android.widget.Button; 
import android.widget.EditText; 
 
public class MainActivity extends ActionBarActivity { 
 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
 
    if (savedInstanceState == null) { 
      getSupportFragmentManager().beginTransaction() 
          .add(R.id.container, new PlaceholderFragment()).commit(); 
    } 
  } 
 
  @Override 
  public boolean onCreateOptionsMenu(Menu menu) { 
 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
  } 
 
  @Override 
  public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
      return true; 
    } 
    return super.onOptionsItemSelected(item); 
  } 
 
  /** 
   * A placeholder fragment containing a simple view. 
   */ 
  public static class PlaceholderFragment extends Fragment { 
 
    public PlaceholderFragment() { 
    } 
 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
        Bundle savedInstanceState) { 
      View rootView = inflater.inflate(R.layout.fragment_main, container, false); 
       
      final EditText numberText=(EditText) rootView.findViewById(R.id.number); 
      Button button=(Button)rootView.findViewById(R.id.button); 
       
      button.setOnClickListener(new OnClickListener() 
      { 
 
        @Override 
        public void onClick(View v) { 
           
          String number=numberText.getText().toString(); 
          Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+number)); 
          startActivity(intent); 
           
           
          // TODO Auto-generated method stub 
           
        } 
         
      }); 
      return rootView; 
    } 
  } 
 
}

以上就是Android中怎么实现一个电话拨号器,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI