在Ubuntu应用中合理使用on-screen-keyboard来使得我们的输入更加便利
2016-04-18 13:54
369 查看
有兴趣的朋友可以阅读我们全球开发者网站的文章"On Screen Keyboard tricks".里面讲了许多的东西.在今天的文章中,我们直接来一个活生生的例程来阐述这个问题.
在上面的例程中,我们有意识地把:
注释掉,我们可以运行我们的应用:
从上面的截图中可以看出来,当我们点击最上面的任何一个输入框时,我们最下面的"Createt Account"按钮就被键盘所在的位置遮住了.那么我们怎么才能可以见到我们的按钮呢?答案就是在我们的MainView中,把如下的开关打开:
再次重新运行我们的应用:
从上面我们可以看出来.当我们点击email进行输入的时候,"Create Account"按钮也自动跑到我们键盘的上面.这样当我们输入完我们的内容的时候,我们可以直接按下按钮来进行创建一个账号,而不用先把键盘弄消失掉,再提交.
整个项目的源码在:https://github.com/liu-xiao-guo/osk
我们来用另外一个例程来展示OSK的用法:
在上面的例程中,当我们注释掉:
运行我们的应用,并在最下面的输入框中点击进行输入:
从上面可以看出来,当我们进行输入的时候,我们的输入框被键盘挡住了.我们看不见我们的输入框.而当我们把下面的属性设为真时:
在重新运行我们的应用:
从上面我们可以看出来,当我们输入的时候我们可以看见我们的输入框,并可以输入为我们所需要的内容.
整个项目的源码在:https://github.com/liu-xiao-guo/osk1
Main.qml
import QtQuick 2.4 import Ubuntu.Components 1.3 /*! \brief MainView with a Label and Button elements. */ MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "osk.liu-xiao-guo" width: units.gu(60) height: units.gu(85) // anchorToKeyboard: true Page { title: i18n.tr("onscreenkeyboard") anchors.fill: parent Flickable { id: sampleFlickable clip: true contentHeight: mainColumn.height + units.gu(5) anchors { top: parent.top left: parent.left right: parent.right bottom: createButton.top bottomMargin: units.gu(2) } Column { id: mainColumn spacing: units.gu(2) anchors { top: parent.top left: parent.left right: parent.right margins: units.gu(2) } TextField { id: username width: parent.width placeholderText: "username" } TextField { id: password width: parent.width placeholderText: "password" } TextField { id: email width: parent.width placeholderText: "email" } } } Button { id: createButton text: "Create Account" anchors { horizontalCenter: parent.horizontalCenter bottom: parent.bottom margins: units.gu(2) } onClicked: { console.log("it is clicked") } } } }
在上面的例程中,我们有意识地把:
anchorToKeyboard: true
注释掉,我们可以运行我们的应用:
从上面的截图中可以看出来,当我们点击最上面的任何一个输入框时,我们最下面的"Createt Account"按钮就被键盘所在的位置遮住了.那么我们怎么才能可以见到我们的按钮呢?答案就是在我们的MainView中,把如下的开关打开:
anchorToKeyboard: true
再次重新运行我们的应用:
从上面我们可以看出来.当我们点击email进行输入的时候,"Create Account"按钮也自动跑到我们键盘的上面.这样当我们输入完我们的内容的时候,我们可以直接按下按钮来进行创建一个账号,而不用先把键盘弄消失掉,再提交.
整个项目的源码在:https://github.com/liu-xiao-guo/osk
我们来用另外一个例程来展示OSK的用法:
Main.qml
import QtQuick 2.4 import Ubuntu.Components 1.3 MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "osk1.liu-xiao-guo" width: units.gu(100) height: units.gu(75) //anchorToKeyboard: true Page { header: PageHeader { id: pageHeader title: i18n.tr("osk1") StyleHints { foregroundColor: UbuntuColors.orange backgroundColor: UbuntuColors.porcelain dividerColor: UbuntuColors.slate } } TextField { anchors.bottom: parent.bottom anchors.horizontalCenter: parent.horizontalCenter anchors.bottomMargin: units.gu(2) placeholderText: "please input something" } } }
在上面的例程中,当我们注释掉:
anchorToKeyboard: true
运行我们的应用,并在最下面的输入框中点击进行输入:
从上面可以看出来,当我们进行输入的时候,我们的输入框被键盘挡住了.我们看不见我们的输入框.而当我们把下面的属性设为真时:
anchorToKeyboard: true
在重新运行我们的应用:
从上面我们可以看出来,当我们输入的时候我们可以看见我们的输入框,并可以输入为我们所需要的内容.
整个项目的源码在:https://github.com/liu-xiao-guo/osk1
相关文章推荐
- BaseAnimation是基于开源的APP,致力于收集各种动画效果(最新版本1.3)
- Jolt Awards: The Best Books
- Apache POI对EXCEL的操作
- dedecms自带CKEditor编辑添加行间距按钮
- Android项目中异常捕获及对应Log日志文件保存
- 【js】canvas——Atomic-particle-motion
- centos 中文字体解决方案
- 算法训练 字串统计
- EL 表达式:jsp中显示实例属性
- 100个直接可以拿来用的JavaScript实用功能代码片段
- virtualbox安装增强功能时【未能加载虚拟光盘】
- vsftpd的搭建
- java常用算法之返回目标数字在有序数组中的位置(假设有序数组中不存在重复数字)
- Oracle-sequence
- mfc 按钮快捷键
- 机器学习方法(八):随机采样方法整理(MCMC、Gibbs Sampling等)
- 百度坐标转化为高德坐标 android
- kafka集群的安装
- IE无法正常打开QC的解决方案
- Matlab 7.1安装及打不开问题解决