6959

ambiguous of the custom_buttonfield

Question:

<a href="http://imageshack.us/photo/my-images/59/320iconnews.png/" rel="nofollow">This</a> is the original button image. The background of the button was transparent.

When apply into apps, the button look like <a href="http://imageshack.us/photo/my-images/72/21387545.png/" rel="nofollow">this</a>. Please look at top left the button. The background of the button became gray instead of transparent.

<a href="http://img20.imageshack.us/img20/1194/sc20120719145312.png" rel="nofollow">Here</a> is the Android version's button.

Not only the button but also all same type of buttons which background was transparent.

The custom_buttonfield

public class Custom_ButtonField extends ButtonField { Bitmap mNormal; Bitmap mFocused; Bitmap mActive; int mWidth; int mHeight; private int color = -1; String text; public Custom_ButtonField(Bitmap normal, Bitmap focused, Bitmap active) { super(CONSUME_CLICK | Field.FOCUSABLE | Field.FIELD_HCENTER | Field.FIELD_VCENTER); mNormal = normal; mFocused = focused; mActive = active; mWidth = mNormal.getWidth(); mHeight = mNormal.getHeight(); setMargin(0, 0, 0, 0); setPadding(0, 0, 0, 0); setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0))); setBorder(VISUAL_STATE_ACTIVE, BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0))); } public Custom_ButtonField(String text, Bitmap normal, Bitmap focused, Bitmap active, int color) { super(CONSUME_CLICK | Field.FOCUSABLE | Field.FIELD_HCENTER | Field.FIELD_VCENTER); this.color = color; mNormal = normal; mFocused = focused; mActive = active; mWidth = mNormal.getWidth(); mHeight = mNormal.getHeight(); setMargin(0, 0, 0, 0); setPadding(0, 0, 0, 0); setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0))); setBorder(VISUAL_STATE_ACTIVE, BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0))); this.text = text; } protected void onFocus(int direction) { super.onFocus(direction); } protected void onUnfocus() { super.onUnfocus(); } protected void paint(Graphics graphics) { int fontcontent; if (Display.getWidth() > 480) fontcontent = 28; else if (Display.getWidth() < 481 && Display.getWidth() > 320) fontcontent = 23; else fontcontent = 18; Bitmap bitmap = null; switch (getVisualState()) { case VISUAL_STATE_NORMAL: bitmap = mNormal; break; case VISUAL_STATE_FOCUS: bitmap = mFocused; break; case VISUAL_STATE_ACTIVE: bitmap = mActive; break; default: bitmap = mNormal; } graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(), bitmap, 0, 0); graphics.setFont(Font.getDefault().derive(Font.BOLD, fontcontent)); graphics.setColor(color); graphics.drawText(text, (mNormal.getWidth() - Font.getDefault() .getAdvance(text)) / 2, ((mNormal.getHeight() - Font .getDefault().getHeight()) / 2) + 10, DrawStyle.HCENTER | DrawStyle.VCENTER); } public int getPreferredWidth() { return mWidth; } public int getPreferredHeight() { return mHeight; } protected void layout(int width, int height) { setExtent(mWidth, mHeight); } }

The loader is here

private Bitmap news = Config_GlobalFunction.Bitmap("icon_news.png"); private Bitmap newsactive = Config_GlobalFunction .Bitmap("icon_news_active.png"); if (left == 1) { newsbtn = new Custom_ButtonField(news, newsactive, newsactive) { protected boolean navigationClick(int status, int time) { Main.getUiApplication().pushScreen( new Menu_PopupMenu(thisid)); return true; } }; add(newsbtn); } else if (left == 2) { backbtn = new Custom_ButtonField(back, backctive, backctive) { protected boolean navigationClick(int status, int time) { Main.getUiApplication().popScreen(mainscreen); return true; } }; add(backbtn); } if (left == 1) { field = getField(1); layoutChild(field, back.getWidth(), back.getHeight()); setPositionChild(field, 10, Height); } else if (left == 2) { field = getField(1); layoutChild(field, news.getWidth(), news.getHeight()); setPositionChild(field, 10, Height); }

if I set like this layoutChild(field, 60, 60);, then it got no problem, the behind gray color no more. However, I cannot set fixed and must dynamic size.

Answer1:

call this setBackground(BackgroundFactory.createBitmapBackground(bitmap)); instead of graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(), bitmap, 0, 0); in Custom_ButtonField.

Answer2:

I can't see the actual code that's loading the Bitmap objects, but I know you were discussing it in the other question you posted. Try this:

Config_GlobalFunction.java:

<pre class="lang-java prettyprint-override">public static Bitmap Bitmap(String name) { Bitmap result; // do whatever you do to load the Bitmap (e.g. Bitmap.getBitmapResource(name)) result.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP); return result; }

Recommend

  • How to detect whether field is touched or clicked?
  • JPanel gets paintComponent gets called when child is entered
  • Color of JOptionPane border
  • Saving data and creating a new panel without that data in it
  • Putting 3 dots at the beginning of JLabel
  • AutoHotKey JavaScript Link
  • Use of subpaint() on Mainscreen Doesn't paint child correctly
  • How to change JLabel when JButton is clicked? [duplicate]
  • My search results aren't consistent? Why is this?
  • preg_match name of input field inside form
  • Add google places autocomplete to newly generated inputs in list items
  • Calculating collision for a moving circle, without overlapping the boundaries
  • Flex header, content, footer layout
  • How to create vertical TitledBorder in JPanel (javax swing)
  • Connecting Azure Function to Azure Storage Blob with HTTP trigger
  • Excel VBA to Highlight Duplicates across a workbook
  • Projecting Objects Out Of Collision
  • lights animation in objective-c
  • VBScript / ADODB Syntax Issue with adArray?
  • Spring Data Neo4j 4returning cached results?
  • Ios swift - storing uiimage in document directory and path in core data
  • How can I create a list of elements with the same xpath using selenium with python?
  • Vertical alignment of legend title (ggplot2)
  • Jacoco exclude classes
  • how to sort the field in the mongo document which is inside array
  • How to apply the same function over a series of columns with a specific string in their names?
  • change border/color onFocus
  • Reading comments from .proto files using a Protocol Buffers descriptor object
  • Consecutive calls/evaluations in a form?
  • R - Phylogram labels to vector
  • Learn Ruby Hard Way ex. 48
  • JQueryMobile: SelectWidget not showing after second page visit
  • Convert ctime to unicode and unicode to ctime python
  • Using SQL stored function gives invalid SQL statement
  • Lync Database - Mobile vs PC users
  • Touch events (touchesMoved) not working on UIViews inside UIScrollView
  • how to calculate distance between two points in google maps?
  • Put percent labels next to legend instead of in the slice
  • HABTM associations in Rails : collecting and counting the categories of a model's children
  • Guava how to copy all files from one directory to another