我想在操作栏标题旁边显示一个微调器,我能知道该怎么做吗?对于普通标题,正在使用“setTitle(”“)”,但如果我想自定义标题而不仅仅是文本视图,这怎么可能。这是mainactivity和baseactivity
public class MainActivity extends BaseActivity{
private Fragment mContent;
public MainActivity(){
super(R.string.app_name);
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if (savedInstanceState != null)
mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
if (mContent == null)
mContent = new MainView();
setContentView(R.layout.content_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, mContent).commit();
setBehindContentView(R.layout.menu_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame, new RandomList()).commit();
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
setSlidingActionBarEnabled(true);
}
@Override
public void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
getSupportFragmentManager().putFragment(outState, "mContent", mContent);
}
public void switchContent(Fragment fragment){
mContent = fragment;
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
getSlidingMenu().showContent();
}
}
public class BaseActivity extends SlidingFragmentActivity {
private int mTitleRes;
protected ListFragment mFrag;
public BaseActivity(int titleRes){
mTitleRes = titleRes;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mTitleRes);
setBehindContentView(R.layout.menu_frame);
FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
mFrag = new RandomList();
ft.replace(R.id.menu_frame, mFrag);
ft.commit();
SlidingMenu sm = getSlidingMenu();
sm.setShadowWidth(15);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffset(60);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case android.R.id.home:
toggle();
return true;
}
return onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
getSupportMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public class BasePagerAdapter extends FragmentPagerAdapter{
private List<Fragment> mFragments = new ArrayList<Fragment>();
private ViewPager mPager;
public BasePagerAdapter(FragmentManager fm, ViewPager vp){
super(fm);
mPager = vp;
mPager.setAdapter(this);
for (int i = 0; i < 3; i++){
addTab(new RandomList());
}
}
public void addTab(Fragment frag){
mFragments.add(frag);
}
@Override
public Fragment getItem(int position){
return mFragments.get(position);
}
@Override
public int getCount(){
return mFragments.size();
}
}
}