1。 SDK下載下傳:
http://developer.bada.com/apis/docs/commonpage.do?menu=MC01040000&mtb1=&mtb2=
看網上很多人抱怨官網的SDK無法下載下傳下來,我當時是用迅雷下的,花了兩天時間才下下來
2。 一些控件的使用
以下的例子沒有特殊說明則都是基于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);