我们都知道每个手机号码,都应该有这样的属性:号码、归属地、运营商等。本文将利用阿里提供的开放接口来获取手机号码的归属地。这个工程也简单地运用了mvp的风格来构建工程结构。(点击:工程地址(码云git) 可以下载或查看工程源码)
1.先看看效果图片
2.再来是工程的目录结构
java
res
3.工程代码文件
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:background="@android:color/darker_gray"
android:gravity="center_vertical"
android:orientation="vertical"
tools:context="com.exmple.phonesearch.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="手机号码归属地查询"
android:textColor="#ffffff"
android:textSize="14sp" />
</RelativeLayout>
<EditText
android:id="@+id/et_phone_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:background="@android:color/background_light"
android:hint="11位手机号"
android:inputType="phone"
android:maxLength="11"
android:maxLines="1" />
<Button
android:id="@+id/btn_search"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:background="@color/colorPrimary"
android:text="查 询"
android:textColor="#ffffff"
android:textSize