TV中一款自定义的软键盘(覆盖了系统原生的键盘)

最近做公司的项目,用到一款自定义的软键盘,觉得挺好看的,在这里分享出来,给网友们借鉴下,希望对大家有用~

效果图如下:





核心代码如下:

private void showKeyboard(EditText etContent) {
this.inputContent = etContent;
View content = View.inflate(this, R.layout.keyborad, null);
ll_key_number_page_1 = (LinearLayout) content.findViewById(R.id.ll_keyboard_number_page_1);
ll_key_number_page_2 = (LinearLayout) content.findViewById(R.id.ll_keyboard_number_page_2);
ll_key_char_lower = (LinearLayout) content.findViewById(R.id.ll_keyboard_lower_char);
ll_key_char_upper = (LinearLayout) content.findViewById(R.id.ll_keyboard_upper_char);
for (int i = 1; i <= 122; i++) {
int resId = getResourdIdByResourdName("tv_" + i);
if (resId > 0) {
View view = content.findViewById(resId);
if (view != null) {
view.setOnClickListener(this);
}
}
}


for (int i = 1; i <= 4; i++) {
int ivResId = getResourdIdByResourdName("iv_" + i);
final ImageView iv_empty = (ImageView) content.findViewById(ivResId);
iv_empty.setOnClickListener(this);
iv_empty.setOnFocusChangeListener(new OnFocusChangeListener() {


@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
iv_empty.setBackground(getResources().getDrawable(R.drawable.key_focus));
iv_empty.setImageDrawable(getResources().getDrawable(R.drawable.empty_focus));
} else {
iv_empty.setBackground(getResources().getDrawable(R.drawable.key));
iv_empty.setImageDrawable(getResources().getDrawable(R.drawable.empty_unfocus));
}
}
});
}


for (int i = 1; i <= 2; i++) {
int ivResId = getResourdIdByResourdName("iv_character_" + i);
final ImageView iv_char = (ImageView) content.findViewById(ivResId);
iv_char.setOnClickListener(this);
iv_char.setOnFocusChangeListener(new OnFocusChangeListener() {


@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
iv_char.setBackground(getResources().getDrawable(R.drawable.key_focus));


} else {
iv_char.setBackground(getResources().getDrawable(R.drawable.key));
}
}
});
}
windows = new PopupWindow(content, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
// !!!重要监听返回键
windows.setBackgroundDrawable(new BitmapDrawable());
windows.showAsDropDown(etContent, 0, 0);


key_char = getString(R.string.key_char_value);
key_character = getString(R.string.key_character_value);
key_page = getString(R.string.key_page_value);
key_lower = getString(R.string.key_character_lower_value);
key_upper = getString(R.string.key_character_upper_value);
key_empty = getString(R.string.key_empty_value);
key_del = getString(R.string.key_del_value);
key_finish = getString(R.string.key_finish_value);
}



具体的源码已经上传到CSDN,可以自行下载,地址如下:

http://download.csdn.net/download/downloadname/10122408


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值