[Bada开发]基于bada1.0的5种控件介绍[待续]
以下的例子没有特殊说明则都是基于bada SDK 1.0.0
包括,图片加载、按钮、文字编辑区、确认框以及选框。
1.图片加载函数
- Osp::Graphics::Bitmap*
- BaseForm::GetBitmapN(const Osp::Base::String& name)
- {
- Bitmap* pBitmap = null;
- Image* pImage = new Image();
- String fullname(L"/Res/");
- fullname.Append(name);
- pImage->Construct();
- if(fullname.EndsWith(L"jpg"))
- {
- pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);
- }
- else if(fullname.EndsWith(L"bmp"))
- {
- pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);
- }
- else if(fullname.EndsWith(L"png"))
- {
- pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_ARGB8888);
- }
- else if (fullname.EndsWith(L"gif"))
- {
- pBitmap = pImage->DecodeN(fullname, BITMAP_PIXEL_FORMAT_RGB565);
- }
- delete pImage;
- return pBitmap;
- }
2.Button
我设置了button的背景图片,例子如下
- Osp::Graphics::Bitmap *__pReturn;
- Osp::Graphics::Bitmap *__pReturnAct;
- static const int ID_BUTTON_RETURN = 100;
- __pReturn = GetBitmapN(L"return.png");
- __pReturnAct = GetBitmapN(L"returnact.png");
- Button *pBtnReturn = new Button();
- pBtnReturn->Construct(Rectangle(x, y, w, h), "");
- pBtnReturn->SetActionId(ID_BUTTON_RETURN);
- pBtnReturn->SetNormalBackgroundBitmap(*__pReturn);
- pBtnReturn->SetPressedBackgroundBitmap(*__pReturnAct);
- pBtnReturn->AddActionEventListener(*this);
- AddControl(*pBtnReturn);
- delete __pReturn;
- delete __pReturnAct;
3.EditField
- Osp::Ui::Controls::EditField* __pAddrEdit;
- __pAddrEdit = new EditField();
- //第二个参数可以根据文本的不同来选择,文本的最大长度可以自定义
- __pAddrEdit->Construct(Rectangle(x, y, w, h), EDIT_FIELD_STYLE_URL_SMALL, INPUT_STYLE_FULLSCREEN, false, 300);
- AddControl(*__pAddrEdit);
- __pAddrEdit->SetEnabled(true);
- __pAddrEdit->SetKeypadEnabled(true);
- __pAddrEdit->SetText (L"http://");
4.CheckButton
- CheckButton *pCheckBtn = new CheckButton();
- pCheckBtn->Construct(Rectangle(x, y, dx, dy),CHECK_BUTTON_STYLE_MARK, BACKGROUND_STYLE_NONE, false, "");
- pCheckBtn->SetActionId(ID_CHECK_BTN_ON, ID_CHECK_BTN_OFF);
- pCheckBtn->SetTextHorizontalAlignment(ALIGNMENT_LEFT); pCheck3G->AddActionEventListener(*this); AddControl(*pCheckBtn);
5.RadioGroup
- CheckButton *pCheckWap = new CheckButton();
- pCheckWap->Construct(Rectangle(x, y, w, h), CHECK_BUTTON_STYLE_RADIO, BACKGROUND_STYLE_NONE, false, L"wap");
- pCheckWap->SetActionId(ID_BUTTON_RADIOWAP_ON, ID_BUTTON_RADIOWAP_OFF);
- pCheckWap->AddActionEventListener(*this);
- AddControl(*pCheckWap);
- CheckButton *pCheckNet = new CheckButton();
- pCheckNet->Construct(Rectangle(x, y, w, h),CHECK_BUTTON_STYLE_RADIO, BACKGROUND_STYLE_NONE, false, L"net");
- pCheckNet->SetActionId(ID_BUTTON_RADIONET_ON, ID_BUTTON_RADIONET_OFF);
- pCheckNet->AddActionEventListener(*this);
- AddControl(*pCheckNet);
- RadioGroup *pRadioGroup = new RadioGroup();
- pRadioGroup->Construct();
- pRadioGroup->Add(*pCheckWap);
- pRadioGroup->Add(*pCheckNet);
- pRadioGroup->SetSelectedItem(*pCheckNet);
- AddControl(*pRadioGroup);