eatwhatApp开发实战(十四)

Posted 宝宝巴士 SD.Team

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了eatwhatApp开发实战(十四)相关的知识,希望对你有一定的参考价值。

  之前我们就输入框EditText做了优化,而这次,我们为app添加拨打电话的功能。

  首先是布局,将activity_shop_info.xml中对应的电话那一栏进行重新设计:

  <RelativeLayout 
	    android:id="@+id/ll_tel"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:layout_below="@id/ll_name">
		<TextView
		    android:id="@+id/tv_text_shop_tel"
		    android:layout_width="wrap_content"
		    android:layout_height="wrap_content"
		    android:text="电话:"
		    android:textSize="20sp"/>   
		<TextView
		    android:id="@+id/tv_shop_tel"
		    android:layout_width="wrap_content"
		    android:layout_height="wrap_content"
		    android:layout_toRightOf="@id/tv_text_shop_tel"
		    android:text="10086"
		    android:textSize="20sp"/> 
		 <Button
		    android:id="@+id/btn_call"
		    android:layout_width="wrap_content"
		    android:layout_height="wrap_content"
		    android:layout_alignParentRight="true"
		    android:onClick="call"
		    android:text="拨打"
		    android:layout_alignBaseline="@id/tv_shop_tel"
		    android:textSize="20sp"/>
	</RelativeLayout>

  app中实现拨打电话的功能,在AndroidManifest.xml中必须添加权限:

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

  之后就可以写对应的实现代码:

    public void call(View v) {
		
		// 获取电话号码栏中的号码
		String num = tel_num.getText().toString();
		// 如果输入不为空创建打电话的Intent
		if (num.trim().length() != 0) {
			Intent phoneIntent = new Intent("android.intent.action.CALL",
					Uri.parse("tel:" + num));
			// 启动
			startActivity(phoneIntent);
		}else {
			// 否则Toast提示一下
			Toast.makeText(ShopInfoActivity.this, "号码无效,或为空", Toast.LENGTH_LONG)
					.show();
		}
	}

  这样,便完成了拨打电话的功能。

 

以上是关于eatwhatApp开发实战(十四)的主要内容,如果未能解决你的问题,请参考以下文章

eatwhatApp开发实战

eatwhatApp开发实战

eatwhatApp开发实战(十三)

SQL开发实战技巧系列(三十四):数仓报表场景☞如何对数据分级并行转为列

SpringBoot--实战开发--压力测试(二十四)

centos mysql 实战 第十四节课