除了 edit 控件外,其它控件若是须要焦点停留功能,能够指定控件的 focusable 属性为 true 来实现。git
在 XML 中,能够这样指定:github
<button ... focusable="true"/>
在 C 代码中,能够这样指定:c#
widget_set_prop_bool(widget, WIDGET_PROP_FOCUSABLE, TRUE);
若是指定了 fucusable 属性为 true,请确保控件的 style 中定义了 focused 状态的数据,不然会由于 focused 状态没有 style 数据而没法显示。如:spa
<style name="default" border_color="#a0a0a0" text_color="black"> <normal bg_color="#f0f0f0" /> <pressed bg_color="#c0c0c0" x_offset="1" y_offset="1"/> <over bg_color="#e0e0e0" /> <focused bg_color="#e0e0e0" /> <disable bg_color="gray" text_color="#d0d0d0" /> </style> <focused bg_color="#e0e0e0" />
#ifndef TK_KEY_MOVE_FOCUS_NEXT #define TK_KEY_MOVE_FOCUS_NEXT "tab" #endif /*TK_KEY_MOVE_FOCUS_NEXT*/
<window anim_hint="htranslate" move_focus_prev_key="up" move_focus_next_key="down">
在这个例子中,方向键 up 移动到前一个焦点控件,方向键 down 移动到下一个焦点控件。code
在一些特殊的硬件设备上,没有触摸屏,只有上、下、左、右、肯定和取消六个键。orm
为了快速切换焦点,AWTK 支持经过左右键切换水平焦点,经过上下键切换垂直焦点。能够经过窗口的下列属性来设置:ip
示例:get
<window text="Custom Soft Keyboard" anim_hint="htranslate" move_focus_up_key="up" move_focus_down_key="down" move_focus_left_key="left" move_focus_right_key="right"> <edit name="edit" x="c" y="10" w="90%" h="30" focused="true" input_type="custom" text="" tips="custom"/> <view y="60" x="c" w="90%" h="-60" is_keyboard="true" grab_keys="true" children_layout="default(r=4,c=4,m=5,s=5)" > <button focusable="true" name="key0" text="0" /> <button focusable="true" name="key1" text="1" /> <button focusable="true" name="key2" text="2" /> <button focusable="true" name="key3" text="3" /> <button focusable="true" name="key4" text="4" /> <button focusable="true" name="key5" text="5" /> <button focusable="true" name="key6" text="6" /> <button focusable="true" name="key7" text="7" /> <button focusable="true" name="key8" text="8" /> <button focusable="true" name="key9" text="9" /> <button focusable="true" name="key#" text="#" /> <button focusable="true" name="backspace" text="<=" /> </view> </window>
在这个例子中,方向键 up 移动到上方的焦点控件,方向键 down 移动到下方的焦点控件。 方向键 left 移动到左方的焦点控件,方向键 right 移动到右方的焦点控件。input
软键盘自己不能获得焦点,为了收到按键消息,须要指定属性 grab_keys="true"。it
能够指定控件的 focused 属性为 true 将控件设置为初始焦点控件。
在 XML 中,能够这样指定:
<button ... focused="true"/>
在 C 中,能够这样指定:
widget_set_prop_bool(widget, WIDGET_PROP_FOCUSED, TRUE);