直播系统代码,自定义软键盘样式:字母、数字、标点三种切换
直播系统代码,自定义软键盘样式:字母、数字、标点三种切换
在需要的调用软键盘的activity_mian.xml中加入键盘控件
1 | <RelativeLayout<br> android:layout_width= "fill_parent" <br> android:layout_height= "wrap_content" <br> android:gravity= "center_horizontal" ><br> <br> <android.inputmethodservice.KeyboardView<br> android:id= "@+id/keyboard_view" <br> android:shadowRadius= "0.0" <br> android:layout_width= "fill_parent" <br> android:layout_height= "wrap_content" <br> android:layout_alignParentBottom= "true" <br> android:focusable= "true" <br> android:focusableInTouchMode= "true" <br> android:keyPreviewLayout= "@layout/key_preview_layout" <br> android:background= "#D6D9DE" <br> android:keyBackground= "@drawable/btn_keyboard_key" <br> android:keyTextColor= "#747474" <br> android:keyTextSize= "36dp" <br> android:paddingTop= "10dp" <br> android:paddingBottom= "10dp" <br> android:paddingLeft= "95dp" <br> android:paddingRight= "95dp" <br> android:visibility= "gone" <br> /><br></RelativeLayout> |
1.1
android:keyPreviewLayout="@layout/key_preview_layout"这个是长按键盘时弹出框的样式,如果不写,系统默认,默认的有时会会看不清
key_preview_layout.xml:
1 | <br><?xml version= "1.0" encoding= "utf-8" ?><br><TextView xmlns:android= "http://schemas.android.com/apk/res/android" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:textSize= "40sp" <br> android:textColor= "@android:color/white" <br> android:gravity= "center" <br> android:background= "#80929299" /> |
1.2
android:keyBackground="@drawable/btn_keyboard_key"按键的形状
1 | <br>btn_keyboard_key.xml:<br> <br><?xml version= "1.0" encoding= "utf-8" ?><br><shape xmlns:android= "http://schemas.android.com/apk/res/android" <br> android:shape= "rectangle" ><br> <solid android:color= "#FFFFFFFF" /><br> <corners android:topLeftRadius= "8dip" <br> android:topRightRadius= "8dip" <br> android:bottomRightRadius= "8dip" <br> android:bottomLeftRadius= "8dip" /><br></shape> |
2.然后在res文件夹下新建文件夹,里面新建三个文件,即每种键盘样式的布局分别为qwerty.xml, symbols.xml, punctuate.xml
字母键盘-qwerty.xml:
1 | <br><?xml version= "1.0" encoding= "UTF-8" ?><br><Keyboard android:keyWidth= "100dp" android:keyHeight= "60dp" <br> android:horizontalGap= "10dp" android:verticalGap= "15dp" <br> xmlns:android= "http://schemas.android.com/apk/res/android" ><br> <Row><br> <Key android:codes= "113" android:keyEdgeFlags= "left" <br> android:keyLabel= "q" /><br> <Key android:codes= "119" android:keyLabel= "w" /><br> <Key android:codes= "101" android:keyLabel= "e" /><br> <Key android:codes= "114" android:keyLabel= "r" /><br> <Key android:codes= "116" android:keyLabel= "t" /><br> <Key android:codes= "121" android:keyLabel= "y" /><br> <Key android:codes= "117" android:keyLabel= "u" /><br> <Key android:codes= "105" android:keyLabel= "i" /><br> <Key android:codes= "111" android:keyLabel= "o" /><br> <Key android:codes= "112" android:keyEdgeFlags= "right" <br> android:keyLabel= "p" /><br> </Row><br> <Row><br> <Key android:horizontalGap= "4.999995%p" android:codes= "97" <br> android:keyEdgeFlags= "left" android:keyLabel= "a" /><br> <Key android:codes= "115" android:keyLabel= "s" /><br> <Key android:codes= "100" android:keyLabel= "d" /><br> <Key android:codes= "102" android:keyLabel= "f" /><br> <Key android:codes= "103" android:keyLabel= "g" /><br> <Key android:codes= "104" android:keyLabel= "h" /><br> <Key android:codes= "106" android:keyLabel= "j" /><br> <Key android:codes= "107" android:keyLabel= "k" /><br> <Key android:codes= "108" android:keyEdgeFlags= "right" <br> android:keyLabel= "l" /><br> </Row><br> <Row><br> <Key android:keyWidth= "110dp" android:codes= "-1" <br> android:keyEdgeFlags= "left" android:isModifier= "true" <br> android:horizontalGap= "33dp" <br> android:isSticky= "true" android:keyIcon= "@drawable/shift" /><br> <Key android:codes= "122" android:keyLabel= "z" android:horizontalGap= "30dp" /><br> <Key android:codes= "120" android:keyLabel= "x" /><br> <Key android:codes= "99" android:keyLabel= "c" /><br> <Key android:codes= "118" android:keyLabel= "v" /><br> <Key android:codes= "98" android:keyLabel= "b" /><br> <Key android:codes= "110" android:keyLabel= "n" /><br> <Key android:codes= "109" android:keyLabel= "m" /><br> <Key android:keyWidth= "110dp" android:codes= "-5" <br> android:horizontalGap= "30dp" <br> android:keyEdgeFlags= "right" android:isRepeatable= "true" <br> android:keyIcon= "@drawable/delete" /><br> </Row><br> <Row android:rowEdgeFlags= "bottom" ><br> <Key android:keyWidth= "110dp" android:codes= "-2" android:horizontalGap= "43dp" <br> android:keyIcon= "@drawable/number" /><br> <Key android:keyWidth= "110dp" android:codes= "46" <br> android:keyIcon= "@drawable/point" /><br> <Key android:keyWidth= "540dp" android:codes= "32" <br> android:isRepeatable= "true" android:keyIcon= "@drawable/space" /><br> <Key android:keyWidth= "110dp" android:codes= "47" <br> android:keyIcon= "@drawable/gang" /><br> <Key android:keyWidth= "110dp" android:codes= "-3" <br> android:keyEdgeFlags= "right" android:keyIcon= "@drawable/complete" /><br> </Row><br></Keyboard> |
以上就是直播系统代码,自定义软键盘样式:字母、数字、标点三种切换, 更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现