Android高級部分第五天。android
1. 兼容包app
ViewPager supportV4ide
ActionbarSherlock佈局
步驟:this
1) 繼承SherlockActivityspa
2) 刪除onCreateOptionsMenu()繼承
3) 主題改成Theme.sherlock、Theme.sherlock.light、事件
Theme.sherlock.light.DarkActionbarget
4) 屬性設置 it
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("標題");
actionBar.setDisplayHomeAsUpEnabled(true);// back按鈕
actionBar.setSubtitle("子標題");
5) 建立菜單
getSupportMenuInflater().inflate(R.menu.main, menu);
6) 菜單事件響應
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case android.R.id.home:
finish();
break;
case R.id.action_settings:
Toast.makeText(this, "設置", Toast.LENGTH_SHORT).show();
break;
case R.id.menu_item_share:
Toast.makeText(this, "分享", Toast.LENGTH_SHORT).show();
break;
2. HoloEveryWhere
使用步驟:
1) 繼承的Activity:org.holoeverywhere.app.Activity
2) 拷貝HoloEveryWhere Demos中的DemoApplication類到項目中,
並配置到清單中
3) 主題修改成:Holo.Theme、Holo.Theme.Light、Holo.Theme.Light.DarkActionbar
3. Fragment(片斷)
使用步驟:
1) 建立一個類,繼承Fragment, 重寫onCreateView()方法
加載佈局,實現事件
2) 在佈局中增長FrameLayout,並設置id
3) Activity繼承FragmentActivity
在onCreate()方法中添加Fragment
FragmentManager fragmentMgr = getSupportFragmentManager();
FragmentTransaction ft = fragmentMgr.beginTransaction();
Fragment fragment = new MyFragment();
ft.add(R.id.content, fragment );
ft.commit();