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();