LWUIT:选项卡 - 如何标记当前选定的选项卡
我有 4 个标签。每个选项卡都由一个按钮表示。这些按钮用于选择当前显示的选项卡。每个按钮都有一个图标和文本。
我想通过更改相应按钮的背景颜色和文本标签颜色来突出显示当前选定的选项卡。我想使用主题和资源编辑器来完成此操作。
我创建了主题并为 UIID“Tab”指定了未选择、选择和按下的样式。我的选项卡在 Sun WTK 中看起来很棒!美好的!但我发现在真正的手机上,选项卡看起来总是未选中。我尝试过诺基亚 5800 XPressMusic 和 C7。为什么有区别?
经过一些实验,我找到了原因 - 按钮可能只有两种状态:未选择和按下。它们永远不会处于选定状态。在模拟器上,当我使用导航键移动到按钮时,它会被选中。
那么,我应该怎么做才能标记当前选项卡呢?
I have 4 tabs. Each tab is represented by a button. Those buttons are used to select the currently displayed tab. Each button has an icon and text.
I'd like to highlight the currently selected tab by changing background color and text label color of the corresponding button. I'd like to do it using Theme and Resource Editor.
I created theme and specified unselected, selected and pressed styles for UIID "Tab". My tabs look great in Sun WTK! Fine! But I found that on a real phone the tabs always look like unselected. I tried on Nokia 5800 XPressMusic and C7. Why the difference?
After some experiments I found out the reason - the buttons may be only in 2 states: unselected and pressed. They never be in the selected state. On the emulator when I move to a button using navi keys, it becomes selected.
So, what should I do to mark the current tab?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用几种不同的方法,尤其是在 1.5 中。
LWUIT 1.5 有一个选项卡组件,它几乎可以为您完成所有操作,并且非常灵活。
它使用调用
setToggleButton(true)
方法的单选按钮。切换按钮的作用类似于单选按钮,因此当您按下组中的按钮时,它会保持按下状态并使用 ToggleButton 样式进行渲染(您可以将 UIID 设置为您想要的任何内容)。请参阅 LWUIT 演示的字体演示部分中使用切换按钮的示例。适用于旧版本 LWUIT 的一个选项是在按下按钮时将按钮的 UIID 设置为不同的值(并将先前选择的按钮的 UIID 恢复为原始值)。
You can use a few different approaches especially in 1.5.
LWUIT 1.5 has a Tabs component which pretty much does everything for you and is remarkably flexible.
It uses radio buttons on which the method
setToggleButton(true)
is invoked. Toggle buttons act like radio buttons so when you press a button in the group it stays pressed and is rendered using the ToggleButton style (you can set the UIID to whatever you want). See a sample of using toggle buttons in the font demo portion of LWUIT demo.An option that will work for older versions of LWUIT is to just set the UIID of the button to a different value when it is pressed (and restore the UIID of the previously selected button to the original value).
我实现了我所需要的。感谢 Shai 和他的榜样。
我没有使用主题属性并在代码中进行了所有自定义。我这样做是因为我没有明白设置唯一的 UIID 如何帮助我,因为问题不在于识别必须更改道具的 UIID,而在于识别要更改的按钮的样式。
下面是我的解决方案的一些重要说明。
addActionListener
。repaint()
。I implemented what I needed. Thanks to Shai and his example.
I didn't use theme properties and made all customizations in the code. I did so because I didn't catch how setting unique UIID can help me, since the problem is not in the identifying the UIID for which the props have to be changed, but in identifying the button's style to be changed.
Below some important notes of my solution.
addActionListener
for the buttons AFTER they have added to the tabs.repaint()
after step 2.