ANDROID自动判断输入是电话,网址或者EMAIL的方法—-LINKIFY的应用

<?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=".WebActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="正在接收中"/>
</LinearLayout>
public class WebActivity extends AppCompatActivity {

    private TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        text = findViewById(R.id.textView);
        text.setText("TEST");

        text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //判断输入的类型是哪种,并与系统连接
                Linkify.addLinks(text, Linkify.WEB_URLS|
                        Linkify.EMAIL_ADDRESSES|Linkify.PHONE_NUMBERS);
            }
        });
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容