Android TV 开发(3)
本文来自网易云社区
作者:孙有军
<LinearLayout
android:id="@+id/input_num_line_3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/input_num_line_2"
android:baselineAligned="false"
android:orientation="horizontal"> <RelativeLayout
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_weight="1"> <TextView
android:id="@+id/input_key_number_4"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:background="@drawable/keyboard_item_selector"
android:focusable="true"
android:gravity="center"
android:text="4"
android:textColor="#ffffff"
android:textSize="30sp"/>
</RelativeLayout> <RelativeLayout
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_weight="1"> <TextView
android:id="@+id/input_key_number_5"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:background="@drawable/keyboard_item_selector"
android:focusable="true"
android:gravity="center"
android:text="5"
android:textColor="#ffffff"
android:textSize="30sp"/>
</RelativeLayout> <RelativeLayout
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_weight="1"> <TextView
android:id="@+id/input_key_number_6"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:background="@drawable/keyboard_item_selector"
android:focusable="true"
android:gravity="center"
android:text="6"
android:textColor="#ffffff"
android:textSize="30sp"/>
</RelativeLayout>
</LinearLayout> <LinearLayout
android:id="@+id/input_num_line_4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/input_num_line_3"
android:baselineAligned="false"
android:orientation="horizontal"> <RelativeLayout
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_weight="1"> <TextView
android:id="@+id/input_key_number_1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:background="@drawable/keyboard_item_selector"
android:focusable="true"
android:gravity="center"
android:text="1"
android:textColor="#ffffff"
android:textSize="30sp"/>
</RelativeLayout> <RelativeLayout
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_weight="1"> <TextView
android:id="@+id/input_key_number_2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:background="@drawable/keyboard_item_selector"
android:focusable="true"
android:gravity="center"
android:text="2"
android:textColor="#ffffff"
android:textSize="30sp"/>
</RelativeLayout> <RelativeLayout
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_weight="1"> <TextView
android:id="@+id/input_key_number_3"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:background="@drawable/keyboard_item_selector"
android:focusable="true"
android:gravity="center"
android:text="3"
android:textColor="#ffffff"
android:textSize="30sp"/>
</RelativeLayout>
</LinearLayout> <TextView
android:id="@+id/show_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/input_num_line_4"
android:layout_centerInParent="true"
android:padding="@dimen/gap_20_dp"
android:textColor="#ffffff"
android:textSize="33sp"/>
</RelativeLayout>
对应的界面代码如下:
public class DialPanFragment extends Fragment implements View.OnClickListener {
private TextView showPhone;
private ImageView dialBnt;
public DialPanFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_dial_pan, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
findViews();
}
private void findViews() {
showPhone = (TextView) getView().findViewById(R.id.show_phone);
dialBnt = (ImageView) getView().findViewById(R.id.dial_icon);
dialBnt.setOnClickListener(this);
dialBnt.setTag(-2);
dialBnt.setEnabled(false);
View view0 = getView().findViewById(R.id.input_key_number_0);
view0.setTag(0);
view0.setOnClickListener(this);
View view1 = getView().findViewById(R.id.input_key_number_1);
view1.setTag(1);
view1.setOnClickListener(this);
view1.setNextFocusUpId(R.id.dial_tab);
View view2 = getView().findViewById(R.id.input_key_number_2);
view2.setTag(2);
view2.setOnClickListener(this);
view2.setNextFocusUpId(R.id.dial_tab);
View view3 = getView().findViewById(R.id.input_key_number_3);
view3.setTag(3);
view3.setOnClickListener(this);
view3.setNextFocusUpId(R.id.dial_tab);
View view4 = getView().findViewById(R.id.input_key_number_4);
view4.setTag(4);
view4.setOnClickListener(this);
View view5 = getView().findViewById(R.id.input_key_number_5);
view5.setTag(5);
view5.setOnClickListener(this);
View view6 = getView().findViewById(R.id.input_key_number_6);
view6.setTag(6);
view6.setOnClickListener(this);
View view7 = getView().findViewById(R.id.input_key_number_7);
view7.setTag(7);
view7.setOnClickListener(this);
View view8 = getView().findViewById(R.id.input_key_number_8);
view8.setTag(8);
view8.setOnClickListener(this);
View view9 = getView().findViewById(R.id.input_key_number_9);
view9.setTag(9);
view9.setOnClickListener(this);
View viewDel = getView().findViewById(R.id.input_key_number_del);
viewDel.setTag(-1);
viewDel.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int tag = (int) v.getTag();
if (tag == -2) {
dial();
} else if (tag == -1) {// DEL
delNumber();
} else {
inputNumber(tag);
}
}
private void delNumber() {
String text = showPhone.getText().toString();
if (text != null && text.length() > 0) {
text = text.substring(0, text.length() - 1);
showPhone.setText(text);
}
dialBtnState(text);
}
private void inputNumber(int tag) {
String text = showPhone.getText().toString();
if (text == null) {
text = new String(String.valueOf(tag));
} else {
text = text + tag;
}
dialBtnState(text);
showPhone.setText(text);
}
private void dial() {
String text = showPhone.getText().toString();
int len = TextUtils.isEmpty(text) ? 0 : text.length();
if (len != 11) {
ToastUtil.showToast("你输入的账号不合法!");
showPhone.setText("");
} else {
String uid = ContactProvider.getUidByPhone(text);
if (TextUtils.isEmpty(uid)) {
ToastUtil.showToast("该账号不存在!");
} else {
// TODO
}
}
}
private void dialBtnState(String text) {
dialBnt.setEnabled(!TextUtils.isEmpty(text));
}
}
网易云免费体验馆,0成本体验20+款云产品!
更多网易研发、产品、运营经验分享请访问网易云社区
相关文章:
【推荐】 网易云易盾CTO朱浩齐:我们是如何用AI赋能内容安全?
【推荐】 如何实现360度的手游安全防护?网易云易盾专家分享最新实践
【推荐】 从细节处谈Android冷启动优化
Android TV 开发(3)的更多相关文章
- Android TV开发总结(六)构建一个TV app的直播节目实例
请尊重分享成果,转载请注明出处:http://blog.csdn.net/hejjunlin/article/details/52966319 近年来,Android TV的迅速发展,传统的有线电视受 ...
- Android TV开发总结(五)TV上屏幕适配总结
前言:前面几篇总结一些TV上的小Sample,开源到GitHub:https://github.com/hejunlin2013/TVSample, 点击链接,可以持续关注.今天总结下TV上屏幕适配. ...
- Android TV开发总结(三)构建一个TV app的焦点控制及遇到的坑
转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼yuiop:http://blog.csdn.net/hejjunlin/article/details/52835829 前言:上篇中,&l ...
- 聊聊真实的 Android TV 开发技术栈
智能电视越来越普及了,华为说四月发布智能电视跳票了,一加也说今后要布局智能电视,在智能电视方向,小米已经算是先驱了.但是还有不少开发把智能电视简单的理解成手机屏幕的放大,其实这两者并不一样. 一.序 ...
- Android TV开发总结(七)构建一个TV app中的剧集列表控件
原文:Android TV开发总结(七)构建一个TV app中的剧集列表控件 版权声明:我已委托"维权骑士"(rightknights.com)为我的文章进行维权行动.转载务必转载 ...
- Android TV开发中所有的遥控器按键监听及注意事项,新增home键监听
原文:Android TV开发中所有的遥控器按键监听及注意事项,新增home键监听 简单记录下android 盒子开发遥控器的监听 ,希望能帮到新入门的朋友们 不多说,直接贴代码 public cla ...
- Android TV开发总结(四)通过RecycleView构建一个TV app列表页(仿腾讯视频TV版)
转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼yuiop:http://blog.csdn.net/hejjunlin/article/details/52854131 前言:昨晚看锤子手 ...
- Android TV开发总结(二)构建一个TV Metro界面(仿泰捷视频TV版)
前言:上篇是介绍构建TV app前要知道的一些事儿,开发Android TV和手机本质上没有太大的区别,屏大,焦点处理,按键处理,是有别于有手机和Pad的实质区别.今天来介绍TV中Metro UI风格 ...
- Android TV 开发 (1)
本文来自网易云社区 作者:孙有军 前言 这里主要记录几个TV问题的解决方案,如果对这个不感兴趣的其实就不用往下看了. 这几天有一个需求就是要求出一个TV版本的app,之前没有具体的了解Tv版的app有 ...
- Android TV开发总结(一)构建一个TV app前要知道的事儿
转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼yuiop:http://blog.csdn.net/hejjunlin/article/details/52792562 前言:近年来,智能 ...
随机推荐
- 【SQL SERVER学习笔记】Sqlserver游标的尝试
DECLARE @ProName NVARCHAR(50)DECLARE @CityName NVARCHAR(50)DECLARE @ProId INT DECLARE @CityId INT DE ...
- js 事件委托 事件代理
JavaScript高级程序设计上解释:事件委托就是利用事件冒泡,只指定一个事件处理程序,就可以管理某一类型的所有事件. 通过例子类比: 有三个同事预计会在周一收到快递.为签收快递,有两种办法:一是三 ...
- Vue nodejs商城项目-商品的分页、排序、筛选
.分页 ,要查第3页的数据,则跳过2*8条数据,然后返回8条数据. 在实现滚动加载时,页面刚一加载完成并不需要请求所有数据,当用户下拉到页面底部时,再去请求数据并拼接到商品数据列表中. 通过vue-i ...
- Django-rest-framework(四)router
在上一节viewsets中,我们提到了route的方式使用,在这一节,我们将仔细介绍drf 的router机制.简单来说,router的作用就是将viewset对象的url映射关系提取出来. 简单使用 ...
- Unity 游戏框架搭建 (十二) 简易AssetBundle打包工具(二)
上篇文章中实现了基本的打包功能,在这篇我们来解决不同平台打AB包的问题. 本篇文章的核心api还是: BuildPipeline.BuildAssetBundles (outPath, 0, Edit ...
- ccenteros 部署 redis
step one : yum install redis -- 安装redis数据库 step two:安装完成之后开启redis 服务 service redis start syste ...
- 第一次接触mysql
一:数据库的好处 1. 可以持久化保存数据在本地 2.结构化查询 二:数据库常见的概念 1.DB: 是datebase数据库的缩写,储存数据得到容器 2.DBMS:数据库管理系统,用于管理数据库,和创 ...
- spring入门(二) 使用注解代替xml配置
1.导包(略) 2.applicationContext.xml如下: <?xml version="1.0" encoding="UTF-8"?> ...
- zepto 基础知识(6)
101.$.ajax $.ajax(options) 类型:XMLttpRequest 执行Ajax请求.他可能是本地资源,或者通过支持HTTP access control的浏览器 或者通过 JSO ...
- bzoj2982: combination(lucas)
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...