LWUIT: Styling a Button

∥☆過路亽.° 提交于 2019-12-11 18:04:44

问题


I have a J2ME LWUIT app and I'm trying to change the width and background color of a button. The button is in a BoxLayout. I'm using code like this:

    btnLogout.setPreferredW(210);
    btnLogout.getStyle().setFgColor(0x00dcc5);
    btnLogout.getStyle().setBgColor(0x302d36);

Only the setFgColor line seems to work. The width remains unchanged and the background remains white. How can I change the style of the button? I haven't had this problem with other components (labels, text fields, etc...)


回答1:


If you are using the nokia sdk 2.0 to build your app, you should know that the Button's and native elements (Checkbox, ComboBox, etc)style is predefined by the system, so you can't change the native background using this methods.

I don't recommend you to change this values. If you want to build an app following the Nokia S40 guidelines, you must keep the native elements as they are.

If you still want to change this background.

You must open the .res file attached to your project (if you have made a custom .res...if you are using the .res from the Nokia sdk...you must find the source code for the library (is nokia page) and there you can find the .res). In the .res file you can create a new style for your custom Button, and later in the code you must set it to your Button, using the setUIID method in your component....with the name that you have set in the .res file.



来源:https://stackoverflow.com/questions/18899811/lwuit-styling-a-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!