简体   繁体   English

如何在J2ME中设置列表的背景色

[英]How to set a background color of a list in j2me

I'm new in J2ME and I'd like to know how to make the background of my list to a color like grey and text into a color like black? 我是J2ME的新手,我想知道如何将列表背景变成灰色,将文本变成黑色。 The tutorials I'm getting are too complex for a beginner, I was wondering whether you guys might care to help. 对于初学者来说,我得到的教程太复杂了,我想知道你们是否愿意提供帮助。

Here is my code. 这是我的代码。

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ExclusiveChoiceList extends MIDlet{
    private Display display;
    private List list;

    public ExclusiveChoiceList() {
      list = new List("Books", Choice.EXCLUSIVE);
    }

public void startApp(){
display = Display.getDisplay(this);
list.append("PHP", null);
list.append("MySQL", null);
list.append("JAVA", null);
list.append("VB.net", null);
list.append("Javascript", null);
display.setCurrent(list);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
}

I would suggest two ways: 我建议两种方式:
1 -You can use LWUIT .You can set Foreground color( The component foreground color that usually refers to the component text color. For example, for a Button it's the text color) and Background color (The component background color) for each component(and so for lists).For example: 1-您可以使用LWUIT 。您可以为每个组件设置前景颜色(通常指组件文本颜色的组件前景颜色。例如,对于Button,它是文本颜色)和背景颜色(组件背景颜色)以及列表)。例如:

Button.bgColor=ff0000   
SoftButton.fgColor= ffffff   

And you can use themes that creates manually or by LWUIT Theme Creator . 您可以使用手动创建的主题,也可以使用由LWUIT Theme Creator创建的主题
For more information about lwuit see LWUIT_Developer_Guide.pdf and specially chapters 10,11. 有关lwuit的更多信息,请参见LWUIT_Developer_Guide.pdf ,尤其是第10,11章。
2 -On the other hand you can extend a canvas for your purpose.You can see a good tutorial and full source code here . 2-另一方面,您可以根据需要扩展画布 。您可以在此处看到一个不错的教程和完整的源代码。
Second way is less time consuming 第二种方式比较省时间

I use J2ME Polish for GUI in Java ME Application. 我在Java ME Application中将J2ME Polish用于GUI。 In J2ME Polish everything is based on case cade style sheet format like in website. 在J2ME Polish中,所有内容都基于案例cade样式表格式,如网站中所示。 There is a file called polish.css to define the style sheet. 有一个名为polish.css的文件来定义样式表。

I use following code in the polish.css for displaying background in list. 我在polish.css中使用以下代码在列表中显示背景。

focused 
{
    background-color: #cccc;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM