jeck猫
Bold 9000上标准媒体应用程序外观的示例删除了无效的ImageShack链接-切片的媒体应用程序删除了死的ImageShack链接-切片图像使用ButtonField的扩展来映射带有按钮的图像:class BitmapButtonField extends ButtonField { Bitmap mNormal; Bitmap mFocused; Bitmap mActive; int mWidth; int mHeight; public BitmapButtonField(Bitmap normal, Bitmap focused, Bitmap active) { super(CONSUME_CLICK); 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))); } protected void paint(Graphics graphics) { 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); } public int getPreferredWidth() { return mWidth; } public int getPreferredHeight() { return mHeight; } protected void layout(int width, int height) { setExtent(mWidth, mHeight); }}将HorizontalFieldManagers放入VerticalFieldManagers中,反之亦然对正常,聚焦和活动状态使用不同的图像如果需要自定义形状的按钮,则可以在super.paint()之后的管理器paint()方法重写中绘制它们其余部分代码:class Scr extends MainScreen implements FieldChangeListener { Bitmap mBmpHeader = Bitmap.getBitmapResource("header.png"); Bitmap mBmpCover = Bitmap.getBitmapResource("cover.png"); Bitmap mBmpTitle = Bitmap.getBitmapResource("title.png"); Bitmap mBmpTimeline = Bitmap.getBitmapResource("timeline.png"); Bitmap mBmpLeftside = Bitmap.getBitmapResource("leftside.png"); Bitmap mBmpPrevNrm = Bitmap.getBitmapResource("btn_prev_normal.png"); Bitmap mBmpPlayNrm = Bitmap.getBitmapResource("btn_play_normal.png"); Bitmap mBmpPauseNrm = Bitmap.getBitmapResource("btn_pause_normal.png"); Bitmap mBmpStopNrm = Bitmap.getBitmapResource("btn_stop_normal.png"); Bitmap mBmpNextNrm = Bitmap.getBitmapResource("btn_next_normal.png"); Bitmap mBmpPrevFcs = Bitmap.getBitmapResource("btn_prev_focused.png"); Bitmap mBmpPlayFcs = Bitmap.getBitmapResource("btn_play_focused.png"); Bitmap mBmpPauseFcs = Bitmap.getBitmapResource("btn_pause_focused.png"); Bitmap mBmpStopFcs = Bitmap.getBitmapResource("btn_stop_focused.png"); Bitmap mBmpNextFcs = Bitmap.getBitmapResource("btn_next_focused.png"); Bitmap mBmpRightside = Bitmap.getBitmapResource("rightside.png"); VerticalFieldManager mMainManager; HorizontalFieldManager mHeaderManager; HorizontalFieldManager mCoverManager; HorizontalFieldManager mTitleManager; HorizontalFieldManager mTimelineManager; HorizontalFieldManager mToolbarManager; BitmapField mHeader; BitmapField mCover; BitmapField mTitle; BitmapField mTimeline; BitmapField mLeftside; BitmapField mRightside; BitmapButtonField mBtnPrev; BitmapButtonField mBtnPlay; BitmapButtonField mBtnPause; BitmapButtonField mBtnStop; BitmapButtonField mBtnNext; public Scr() { add(mMainManager = new VerticalFieldManager()); addHeader(); addCover(); addTitle(); addTimeline(); addToolbar(); } private void addHeader() { mMainManager.add(mHeaderManager = new HorizontalFieldManager()); mHeaderManager.add(mHeader = new BitmapField(mBmpHeader)); } private void addCover() { mMainManager.add(mCoverManager = new HorizontalFieldManager()); mCoverManager.add(mCover = new BitmapField(mBmpCover)); } private void addTitle() { mMainManager.add(mTitleManager = new HorizontalFieldManager()); mTitleManager.add(mTitle = new BitmapField(mBmpTitle)); } private void addTimeline() { mMainManager.add(mTimelineManager = new HorizontalFieldManager()); mTimelineManager.add(mTimeline = new BitmapField(mBmpTimeline)); } private void addToolbar() { mMainManager.add(mToolbarManager = new HorizontalFieldManager()); mToolbarManager.add(mLeftside = new BitmapField(mBmpLeftside)); mToolbarManager.add(mBtnPrev = new BitmapButtonField(mBmpPrevNrm, mBmpPrevFcs, mBmpPrevFcs)); mToolbarManager.add(mBtnPlay = new BitmapButtonField(mBmpPlayNrm, mBmpPlayFcs, mBmpPlayFcs)); mBtnPlay.setChangeListener(this); mBtnPause = new BitmapButtonField(mBmpPauseNrm, mBmpPauseFcs, mBmpPauseFcs); mBtnPause.setChangeListener(this); mToolbarManager.add(mBtnStop = new BitmapButtonField(mBmpStopNrm, mBmpStopFcs, mBmpStopFcs)); mToolbarManager.add(mBtnNext = new BitmapButtonField(mBmpNextNrm, mBmpNextFcs, mBmpNextFcs)); mToolbarManager.add(mRightside = new BitmapField(mBmpRightside)); } public void fieldChanged(Field field, int context) { if (mBtnPlay == field) play(); else if (mBtnPause == field) pause(); } private void pause() { mToolbarManager.replace(mBtnPause, mBtnPlay); } private void play() { mToolbarManager.replace(mBtnPlay, mBtnPause); }}