我正在编写一个必须从服务运行的应用程序,以便在后台启用连续视频流。我尝试在其中实现导航抽屉,甚至可以通过从屏幕边缘滑动手指来打开滑动菜单,但是无法通过openDrawer(...)或closeDrawer(...)和滑动菜单切换也没有正确打开。列表视图不是弹出菜单,而是慢慢地拖到手指后面,也不能再完全隐藏。这是服务的代码:
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
params = new WindowManager.LayoutParams(width, height,
WindowManager.LayoutParams.TYPE_PRIORITY_PHONE, 8, -3);
layout = (android.support.v4.widget.DrawerLayout) layoutInflater
.inflate(R.layout.recording_service, null);
leftDrawer = (ListView) layout.findViewById(R.id.left_drawer);
adapter = new StableArrayAdapter(this, preferences.getString(
COUNTRYCODE, getApplicationContext().getResources()
.getConfiguration().locale.getCountry()));
leftDrawer.setAdapter(adapter);
wm.addView(layout, params);
return START_STICKY;
}
,这是xml:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:theme="@android:style/Theme.NoTitleBar"
tools:context=".MainActivity" >
<SurfaceView
android:id="@+id/surfaceview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</SurfaceView>
</RelativeLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
非常感谢您的任何帮助。