我已经通过在清单中使用以下行将Sherlock操作栏添加到活动中:
android:theme="@style/Theme.Sherlock.Light"
我希望默认情况下可以节省屏幕空间并隐藏操作栏,只有用户在屏幕上点击时才显示。我在Aldiko应用程序中看到过这种设置,但不知道如何实现。
欢迎任何帮助。
我已经通过在清单中使用以下行将Sherlock操作栏添加到活动中:
android:theme="@style/Theme.Sherlock.Light"
要隐藏,请在您的活动onCreate()
方法中使用以下代码:
getSupportActionBar().hide();
在触摸事件上显示以下代码:
getSupportActionBar().show();
请查看ActionBarSherlock使用指南以获取更多详细信息。
首先给你的活动布局(main_layout.xml)的包装节点分配一个id:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/containerMain"
接下来在你的活动中实现此功能:
boolean isActionBarShow=true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
a=getSupportActionBar();
RelativeLayout rl= (RelativeLayout)findViewById(R.id.containerMain);
rl.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction()==MotionEvent.ACTION_DOWN)
if (isActionBarShow)
{
a.hide();
isActionBarShow=false;
}
else
{
a.show();
isActionBarShow=true;
}
return false;
}
});