04-18-2009 03:21 AM
Hi
I have a MainScreen with a black background and I am trying to add a custom button on top of it with an image as its background. But the custom button has a white border around it.
Is there any way to remove that white border or make it black?
Thanks
Solved! Go to Solution.
04-18-2009 08:16 AM
Override paint method of that button and paint black background and see if it works..
Cheers...
04-18-2009 08:57 AM
Thanks mantaker
Tried that already before posting the question. It doesn't make any difference. Even the getPreferredHeight and width methods return the exact height and width of the background image. But the border still persists.
04-18-2009 09:05 AM
Can you post the piece of code so that I can test it my side?
Cheers..
04-18-2009 09:17 AM
04-18-2009 09:21 AM
Your MainScreen background is Black and you have a custom button(button with image) on which the border is shown white.. Am I right?
I will try to reproduce this issue on my side..
Cheers..
04-18-2009 01:51 PM
Posting the code
This is the custom main screen (created to have a black background)
public class CustomMainScreen extends MainScreen { private VerticalFieldManager container; public CustomMainScreen(String title) { super(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR); setTitle(title); VerticalFieldManager internalManager = new VerticalFieldManager( Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR) { public void paintBackground(Graphics g) { g.clear(); int color = g.getColor(); g.setColor(Color.BLACK); g.fillRect(0, 0, Display.getWidth(), Display.getHeight()); g.setColor(color); } protected void sublayout(int maxWidth, int maxHeight) { /*super.sublayout(maxWidth, maxHeight); XYRect extent = getExtent(); int width = Math.max(extent.width, Display.getWidth()); int height = Math.max(extent.height, Display.getHeight()); setExtent(width, height);*/ Field titleField = getMyTitleField(); int titleFieldHeight = 0; if(titleField != null){ titleFieldHeight = titleField.getHeight(); } int displayWidth = Display.getWidth(); int displayHeight = Display.getHeight(); super.sublayout(displayWidth, displayHeight - titleFieldHeight); setExtent(displayWidth, displayHeight - titleFieldHeight); } }; container = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR); internalManager.add(container); super.add(internalManager); } public void add(Field field) { container.add(field); } private Field getMyTitleField() { Manager delegate = getDelegate(); Field titleField = null; try{ titleField = delegate.getField(0); } catch(Exception e){ e.printStackTrace(); } return titleField; } }
Here's the Main screen which is actually displayed
public class MyMainScreen extends CustomMainScreen implements FieldChangeListener{ MyApplication _uiApp; private VerticalFieldManager hfm = new VerticalFieldManager(VerticalFieldManager.FIELD_VC
ENTER | Manager.FIELD_HCENTER); public MyMainScreen(){ super("Test Title"); _uiApp = (MyApplication) UiApplication.getUiApplication(); Bitmap myBitmap = Bitmap.getBitmapResource("icImg.png"); BitmapField icImg = new BitmapField(myBitmap, BitmapField.NON_FOCUSABLE); hfm.add(icImg); RichTextField rtf = new RichTextField(Field.NON_FOCUSABLE){ public void paint(Graphics graphics){ graphics.setBackgroundColor(Color.BLACK); graphics.clear(); super.paint(graphics); } public int getPreferredHeight(){ return 50; } }; hfm.add(rtf); CustomButton installBtn = new CustomButton("btn_over.png", "btn.png", Field.FOCUSABLE); installBtn.setChangeListener(this); hfm.add(installBtn); add(hfm); } public boolean keyChar(char key, int status, int time) { boolean retval = false; switch (key) { case Characters.ESCAPE: close(); retval = true; break; } return retval; } public boolean onClose() { // exit the application if user chooses to close it from main menu System.exit(0); return true; } public void fieldChanged(Field field, int context) { if (field instanceof CustomButton) { //go to next screen where we start installing the tones OtherScreen scr = new OtherScreen(); _uiApp.pushScreen(scr); } } }
This is the custom button class
public class CustomButton extends Field { private Bitmap _currentPicture; private Bitmap _onPicture; private Bitmap _offPicture; CustomButton (String onImage, String offImage, long style){ super(style); _offPicture = Bitmap.getBitmapResource(offImage); _onPicture = Bitmap.getBitmapResource(onImage); _currentPicture = _onPicture; } public int getPreferredHeight(){ return 45; } public int getPreferredWidth(){ return 170; } protected void onFocus(int direction){ _currentPicture = _offPicture; invalidate(); } protected void onUnfocus(){ _currentPicture = _onPicture; invalidate(); } protected void layout(int width, int height) { setExtent(Math.min( width, getPreferredWidth()), Math.min( height, getPreferredHeight())); } protected void paint(Graphics graphics) { graphics.setBackgroundColor(Color.BLACK); graphics.clear(); graphics.fillRect(0, 0, getWidth(), getHeight()); graphics.drawBitmap(0, 0, getWidth(), getHeight(), _currentPicture, 0, 0); } protected boolean navigationClick(int status, int time){ fieldChangeNotify(1); return true; } }
04-18-2009 02:02 PM
04-19-2009 02:34 AM - edited 04-19-2009 02:37 AM
Thanks Martin. That works.
Can someone also please tell me why HCENTER and VCENTER don't work with the above code. My fields are all left aligned no matter what style I give for the VerticalFieldManager in MyMainScreen.
Thanks again
06-12-2009 02:23 PM