我有一個按鈕字段。它的顏色是紅色的。當我點擊它的顏色按鈕應該變成黑色如何做到這一點?如何更改點擊按鈕的顏色
1
A
回答
1
您是否嘗試過本教程「Blackberry Custom Button Field」,或者您也可以製作背景設置爲一種顏色的位圖字段,併爲所需更改實施自定義繪畫方法。
1
如果您的按鈕是一個a class="button"
標籤,你可以做這樣的:
a.button {
color: black;
}
1
可以與RIM官方文檔的"Tutorial: Creating a custom button"嘗試。
我覺得這是你尋找
0
什麼用 -
image1的是紅色的彩色圖像按鈕和圖像2是黑色
reg_can_btn editprofile = new reg_can_btn("", Field.FOCUSABLE |FIELD_HCENTER, image1, image2, 0x102839);
然後
public class edit_profile_btn extends Field {
private String _label;
private int _labelHeight;
private int _labelWidth;
private Font _font;
private Bitmap _currentPicture;
private Bitmap _onPicture;
private Bitmap _offPicture;
int color;
public edit_profile_btn(String text, long style ,String img, String img_hvr, int color){
super(style);
_offPicture = Bitmap.getBitmapResource(img);
_onPicture = Bitmap.getBitmapResource(img_hvr);
_font = getFont();
_label = text;
_labelHeight = _onPicture.getHeight();
_labelWidth = _onPicture.getWidth();
this.color = color;
_currentPicture = _offPicture;
}
/**
* @return The text on the button
*/
String getText(){
return _label;
}
/**
* Field implementation.
* @see net.rim.device.api.ui.Field#getPreferredHeight()
*/
public int getPreferredHeight(){
return _labelHeight;
}
/**
* Field implementation.
* @see net.rim.device.api.ui.Field#getPreferredWidth()
*/
public int getPreferredWidth(){
return _labelWidth;
}
/**
* Field implementation. Changes the picture when focus is gained.
* @see net.rim.device.api.ui.Field#onFocus(int)
*/
protected void onFocus(int direction) {
_currentPicture = _onPicture;
invalidate();
}
/**
* Field implementation. Changes picture back when focus is lost.
* @see net.rim.device.api.ui.Field#onUnfocus()
*/
protected void onUnfocus() {
_currentPicture = _offPicture;
invalidate();
}
/**
* Field implementation.
* @see net.rim.device.api.ui.Field#drawFocus(Graphics, boolean)
*/
protected void drawFocus(Graphics graphics, boolean on) {
// Do nothing
}
/**
* Field implementation.
* @see net.rim.device.api.ui.Field#layout(int, int)
*/
protected void layout(int width, int height) {
setExtent(Math.min(width, getPreferredWidth()),
Math.min(height, getPreferredHeight()));
}
/**
* Field implementation.
* @see net.rim.device.api.ui.Field#paint(Graphics)
*/
protected void paint(Graphics graphics){
// First draw the background colour and picture
//graphics.setColor(this.color);
graphics.setBackgroundColor(Color.BLACK);
graphics.fillRect(0, 0, getWidth(), getHeight());
graphics.drawBitmap(0, 0, getWidth(), getHeight(), _currentPicture, 0, 0);
// Then draw the text
graphics.setColor(Color.BLACK);
graphics.setFont(_font);
graphics.drawText(_label, 4, 2,
(int)(getStyle() & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK),
getWidth() - 6);
}
/**
* Overridden so that the Event Dispatch thread can catch this event
* instead of having it be caught here..
* @see net.rim.device.api.ui.Field#navigationClick(int, int)
*/
protected boolean navigationClick(int status, int time){
fieldChangeNotify(1);
return true;
}
}
1
試試這個它是工作,
public int checkBoxFlag1 = 0;
public int checkBoxFlag2 = 0;
public int checkBoxFlag3 = 0;
final Bitmap focuscheckButton = Bitmap.getBitmapResource("checkbox_tickmark.png");
final Bitmap unfocuscheckButton = Bitmap.getBitmapResource("checkbox.png");
HorizontalFieldManager checkBoxFieldManager = new HorizontalFieldManager();
BitmapField checkBox1 = new BitmapField(unfocuscheckButton,Field.FOCUSABLE)
{
protected void paint(Graphics graphics)
{
// TODO Auto-generated method stub
if(checkBoxFlag1==0)
{
this.setBitmap(unfocuscheckButton);
}
else
{
this.setBitmap(focuscheckButton);
}
super.paint(graphics);
}
protected boolean navigationClick(int status, int time)
{
// TODO Auto-generated method stub
if(checkBoxFlag1==0)
{
checkBoxFlag1=1;
}
else
{
checkBoxFlag1=0;
}
return super.navigationClick(status, time);
}
};
checkBox1.setMargin(0,20,0,20);
checkBoxFieldManager.add(checkBox1);
相關問題
- 1. 如何更改顏色點擊按鈕?
- 2. 更改點擊按鈕的顏色
- 3. 點擊更改javafx按鈕顏色?
- 4. 如何在Android中點擊時更改按鈕的顏色?
- 5. 如何保存在用戶點擊的按鈕更改顏色
- 6. 離子 - 如何更改點擊時的按鈕顏色
- 7. 如何更改按鈕上的組件顏色點擊
- 8. 更改按鈕點擊按鈕顏色暫時在C#
- 9. 點擊(Javascript)時如何更改按鈕顏色?
- 10. 如何通過點擊按鈕來更改網格顏色?
- 11. 點擊按鈕顏色沒有改變
- 12. 更改NavigationDrawer的顏色點擊顏色
- 13. 如何更改UIActionsheet按鈕的顏色?
- 14. 如何更改按鈕的顏色
- 15. 更改顏色的按鈕
- 16. 使用javascript更改點擊按鈕的div的字體顏色
- 17. 更改點擊按鈕上的圓圈顏色
- 18. 更改背景顏色的按鈕點擊
- 19. Windows Phone 7(WP7)點擊更改按鈕的背景顏色
- 20. 問題有關更改按鈕的顏色點擊
- 21. 如何改變點擊時的按鈕顏色
- 22. 點擊後如何改變按鈕的顏色?
- 23. 如果子按鈕與點擊按鈕相同,則更改div顏色
- 24. 如何更改按鈕顏色?
- 25. 如何更改WinForms按鈕顏色?
- 26. 如何更改按鈕顏色
- 27. 如何點擊和取消點擊按鈕上的顏色?
- 28. 更改按鈕顏色onClick
- 29. 更改按鈕前景色點擊
- 30. 如何在WP7中單擊時更改按鈕的顏色?
你想改變什麼,背景顏色或文字顏色? – donturner