我目前正在使用出色的 ActionBarSherlock ( http://actionbarsherlock.com/ ) 以及运行良好的 jfeinstein 的滑动菜单。我希望能够在用户不活动时自动隐藏操作栏。因此,如果用户在 10 秒内未触摸屏幕,则操作栏将隐藏,活动将全屏显示。如果用户随后再次触摸屏幕,则操作栏会重新出现。这可能吗?我必须从活动类或片段类中执行此操作吗?我会很感激任何建议。
请找到我的主要活动的代码:
public class MainActivity extends SlidingFragmentActivity {
protected ListFragment mFrag;
public MainActivity(){
super();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
setSlidingActionBarEnabled(true);
// set the Behind View
setBehindContentView(R.layout.menu_frame);
if (savedInstanceState == null) {
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new SampleListFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
} else {
mFrag = (ListFragment)this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
}
// set the Above View
setContentView(R.layout.content_frame);
this.getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, new StartUpFragment())
.commit();
// customize the SlidingMenu
SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
//sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Handle other fragments here
// Setup SlidingMenu again
setBehindContentView(R.layout.menu_frame);
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new SampleListFragment();
t.add(R.id.menu_frame, mFrag);
t.commit();
SlidingMenu slidingMenu = getSlidingMenu();
slidingMenu.setBehindScrollScale((float) 0.0);
slidingMenu.setBehindWidthRes(R.dimen.actionbar_home_width);
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
slidingMenu.setSelectorEnabled(true);
slidingMenu.setSlidingEnabled(true);
}
private void setRetainInstance(boolean b) {
// TODO Auto-generated method stub
return;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
//this configures - clicking the icon also makes the sliding menu slide
case android.R.id.home:
toggle();
return true;
}
return super.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 SampleListFragment());
}
}
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();
}
}
}