android keyboard颜色,Android基于KeyboardView和Keyboard实现自定义软键盘 自定义键盘背景色...

Android基于KeyboardView和Keyboard实现自定义软键盘

在一些特别的情况下我们需要去自定义键盘

例如: 银行app的密码输入之类的

笨方法就是直接使用布局写我们的自定义软键盘

但这样写的话我们的代码量就很多

Android官方提供了KeyboardView和Keyboard两个类

我们可以用这两个类去实现自己的软键盘

Demo 已上传 GitHub

https://github.com/pengchengfuGit/DIYKeyboard.git

1.主界面的布局与代码

这是我们主界面的xml

android:layout_width="match_parent"

android:background="@android:color/darker_gray"

android:layout_height="match_parent">

android:layout_width="match_parent"

android:layout_height="50dp" />

android:background="@android:color/white"

android:layout_width="match_parent"

android:keyBackground="@android:color/holo_purple"

android:keyTextColor="#333333"

android:focusable="true"

android:focusableInTouchMode="true"

android:paddingTop="1dp"

android:shadowColor="#FFFFFF"

android:shadowRadius="0.0"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true" />

RelativeLayout>

主界面的Activity 这里写了个KeyBoardUtil来初始的我们自定义软键盘

public class MainActivity extends Activity {

@Override

public void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_payment);

final KeyboardView keyboard = (KeyboardView) findViewById(R.id.kv_keyboard);

final EditText editText = (EditText) findViewById(R.id.et);

//在我们点EditText的时候弹出我们的软键盘

editText.setOnTouchListener(new View.OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

if(editText.hasFocus()){

//用来初始化我们的软键盘

new KeyBoardU

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值