最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android studio案例之實(shí)現(xiàn)電話撥號(hào)

 更新時(shí)間:2021年04月12日 11:26:35   作者:天會(huì)晴就會(huì)暗  
這篇文章主要介紹了Android studio案例之實(shí)現(xiàn)電話撥號(hào),并有詳細(xì)的步驟和實(shí)現(xiàn)代碼,對(duì)此感興趣的同學(xué),可以參考下

 一、代碼配置

1、創(chuàng)建項(xiàng)目

流程看圖

2、增添代碼

更改布局

布局完整代碼

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="電話撥號(hào)"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</LinearLayout>

插入圖片

activity_main_xml文件布局

完整代碼

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="電話撥號(hào)"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="輸入電話號(hào)碼"
        android:inputType="number"
        android:id="@+id/phoneNum"/>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/call"
            android:layout_centerInParent="true" 
            android:id="@+id/call_btn"/>
    </RelativeLayout>
</LinearLayout>

效果展示

mainactivity.java文件

 EditText phoneNum;
    ImageButton call_btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        phoneNum=(EditText) findViewById(R.id.phoneNum);
        call_btn=(ImageButton) findViewById(R.id.call_btn);
       call_btn.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               Intent intent=new Intent();
               intent.setAction(Intent.ACTION_CALL);
               intent.setData(Uri.parse("tel:"+phoneNum.getText()));
               startActivity(intent);

圖片

運(yùn)行代碼

撥號(hào)嘗試,出現(xiàn)報(bào)錯(cuò),需要設(shè)置對(duì)應(yīng)權(quán)限

3、權(quán)限請(qǐng)求

Androidmainfest.xml文件中

<uses-permission android:name="android.permission.CALL_PHONE"/>

Android 6.0以上需要自己手動(dòng)賦予權(quán)限。

應(yīng)用程序權(quán)限請(qǐng)求
版本號(hào)判斷方法

protected boolean shouldAskPermissions(){
    return (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1);
}

權(quán)限申請(qǐng)方法

protected void askPermissions() {
    String[] permissions = {
            "android.permission.CALL_PHONE"
    };
    int requestCode = 200;
    requestPermissions(permissions, requestCode);
}

在onCreate中調(diào)用

if(shouldAskPermissions()){
    askPermissions();
}

請(qǐng)求權(quán)限加入代碼時(shí)要保證程序處于運(yùn)行狀態(tài),不然代碼加進(jìn)去會(huì)報(bào)錯(cuò)。

二、效果演示

隨便輸入得數(shù)字號(hào)碼,提示為空號(hào)。

以上就是Android studio案例之實(shí)現(xiàn)電話撥號(hào)的詳細(xì)內(nèi)容,更多關(guān)于Android studio電話撥號(hào)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Android登錄代碼MVP架構(gòu)詳解

    Android登錄代碼MVP架構(gòu)詳解

    這篇文章主要為大家詳細(xì)介紹了Android登錄代碼MVP架構(gòu)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Android實(shí)現(xiàn)SQLite添加、更新及刪除行的方法

    Android實(shí)現(xiàn)SQLite添加、更新及刪除行的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)SQLite添加、更新及刪除行的方法,涉及Android基于SQLiteDatabase類操作SQLite數(shù)據(jù)庫的基本技巧,需要的朋友可以參考下
    2016-08-08
  • Android?雙屏異顯自適應(yīng)Dialog的實(shí)現(xiàn)

    Android?雙屏異顯自適應(yīng)Dialog的實(shí)現(xiàn)

    Android 多屏互聯(lián)的時(shí)代,必然會(huì)出現(xiàn)多屏連接的問題,本文主要介紹了Android?雙屏異顯自適應(yīng)Dialog的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-12-12
  • Android 百分比布局詳解及實(shí)例代碼

    Android 百分比布局詳解及實(shí)例代碼

    這篇文章主要介紹了Android 百分比布局詳解及實(shí)例代碼的相關(guān)資料,這里附有代碼實(shí)例幫助大家學(xué)習(xí)參考,如何實(shí)現(xiàn)百分比布局,需要的朋友可以參考下
    2016-11-11
  • Android的簡(jiǎn)單前后端交互(okHttp+springboot+mysql)

    Android的簡(jiǎn)單前后端交互(okHttp+springboot+mysql)

    這篇文章主要介紹了Android的簡(jiǎn)單前后端交互(okHttp+springboot+mysql),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • Android中圖片的三級(jí)緩存機(jī)制

    Android中圖片的三級(jí)緩存機(jī)制

    這篇文章主要介紹了Android中圖片的三級(jí)緩存機(jī)制的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-08-08
  • flutter?text組件使用示例詳解

    flutter?text組件使用示例詳解

    這篇文章主要為大家介紹了flutter?text組件使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • Android編程之分辨率處理相關(guān)代碼段合集

    Android編程之分辨率處理相關(guān)代碼段合集

    這篇文章主要介紹了Android編程之分辨率處理相關(guān)代碼段合集,涉及Android針對(duì)分辨率的計(jì)算與轉(zhuǎn)換等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-11-11
  • Android編程實(shí)現(xiàn)讀取工程中的txt文件功能

    Android編程實(shí)現(xiàn)讀取工程中的txt文件功能

    這篇文章主要介紹了Android編程實(shí)現(xiàn)讀取工程中的txt文件功能,結(jié)合實(shí)例形式詳細(xì)分析了Android讀取txt文件的原理、操作步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2017-02-02
  • Android仿淘寶頭條基于TextView實(shí)現(xiàn)上下滾動(dòng)通知效果

    Android仿淘寶頭條基于TextView實(shí)現(xiàn)上下滾動(dòng)通知效果

    這篇文章主要介紹了Android TextView實(shí)現(xiàn)上下滾動(dòng)通知效果,需要的朋友可以參考下
    2017-03-03

最新評(píng)論

祁阳县| 六枝特区| 盐池县| 康定县| 宝应县| 简阳市| 光山县| 郧西县| 崇明县| 揭东县| 尉氏县| 扶余县| 任丘市| 涿州市| 沁水县| 凤翔县| 个旧市| 武定县| 蓝山县| 舟曲县| 江都市| 大姚县| 洞头县| 汶川县| 航空| 那坡县| 太保市| 镇安县| 阳新县| 呈贡县| 和林格尔县| 美姑县| 青河县| 祁门县| 博罗县| 普定县| 兴和县| 石家庄市| 于都县| 保康县| 宁津县|