eatwhatApp开发实战(十四)
2016-03-05 12:34
225 查看
之前我们就输入框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(); } }
这样,便完成了拨打电话的功能。
相关文章推荐
- SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-006- 使用thymeleaf(TemplateResolver、SpringTemplateEngine、ThymeleafViewResolver、th:include、th:object、th:field="*{firstName}")
- 初次使用Android Studio的配置问题
- swift 调用第三方的oc 方法
- elasticsearch小记之—— unmapped_type的使用
- Spring boot app动态更新数据库表
- eclipse中查看Android源代码
- (苹果AppleWWDRCA.cer证书过期)Failed to locate or generate matching signing assets
- cocos2dx在mac下的app打包方法
- android小技巧之TextView设置不同字体大小及样式
- 微信浏览器取消缓存的方法
- Android stdio导入项目后报图片问题(app:mergeDebugResources)
- 微信企业号平台开发之获取菜单,创建菜单和删除菜单
- TRIM:提升磁盘性能,缓解Android卡顿
- java小程序
- iOS:App Extension Keyboard自定义高度
- Android最简单的左右滑动轮播图,以及自动滚动
- 设置Android的ProgressBar的实时进度及比例
- android 开发 system/app目录下面有多个重复包名的apk,会不会冲突
- android控件的隐藏与显示
- Android ViewGroup事件分发机制总结