在安卓中创建弹出窗口的java问题
我试图添加一个选项,供用户使用弹出窗口选择主题。但是,当在我的导航抽屉中单击相应的项目时,不会显示弹出窗口。我有以下处理导航抽屉项目点击的代码:
drawerRecyclerView = (RecyclerView)findViewById(R.id.drawer_recycler);
drawerRecyclerView.setLayoutManager(new LinearLayoutManager(this));
drawerRecyclerView.addOnItemTouchListener(
new RecyclerItemClickListener(getApplicationContext(), new RecyclerItemClickListener.OnItemClickListener() {
@Override public void onItemClick(View view, int position) {
Log.e("STATUS:","User has clicked item: " + String.valueOf(position));
switch (position){
case 1: //MP1
new infoGetter("MP1").execute();
break;
case 2: //MP2
new infoGetter("MP2").execute();
break;
case 3: //MP3
new infoGetter("MP3").execute();
break;
case 4: //MP4
new infoGetter("MP4").execute();
break;
case 5: //Schedule
break;
case 6: //Attendance
break;
case 7: //Theme
popupLayout = (RelativeLayout)findViewById(R.id.theme);
popupWindow = new PopupWindow(popupLayout);
popupWindow.setContentView(popupLayout);
popupWindow.showAtLocation(view, Gravity.CENTER,0,0);
break;
default:
break;
}
drawerLayout.closeDrawers();
}
})
);
我的主题布局如下:
theme_fragment.xml
<RelativeLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="300dp"
安卓:layout_height="350dp"
安卓:layout_gravity="center_vertical|center_horizontal"
安卓:gravity="center_horizontal"
安卓:id="@+id/theme"
安卓:background="@drawable/rounded_popup"
>
<TextView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:textAppearance="?安卓:attr/textAppearanceMedium"
安卓:text="Select Theme:"
安卓:id="@+id/textView"
安卓:gravity="center_horizontal|top"
安卓:textColor="@color/primary_material_light"
安卓:textStyle="bold"
安卓:layout_alignParentTop="true"
安卓:layout_centerHorizontal="true"
安卓:layout_marginTop="50dp" />
<RelativeLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_gravity="center_vertical"
安卓:gravity="center_horizontal"
安卓:layout_marginTop="50dp"
安卓:layout_below="@+id/textView"
安卓:layout_alignParentLeft="true"
安卓:layout_alignParentStart="true">
<CheckBox
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:text="Material Red"
安卓:id="@+id/theme_red"
安卓:layout_gravity="center_horizontal"
安卓:textColor="@color/primary_material_light"
安卓:checked="false"
安卓:textStyle="bold"
安卓:textSize="15sp"
安卓:enabled="true"
安卓:focusable="false" />
<CheckBox
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:text="Material Green"
安卓:id="@+id/theme_green"
安卓:layout_gravity="center_horizontal"
安卓:textColor="@color/primary_material_light"
安卓:checked="false"
安卓:textStyle="bold"
安卓:textSize="15sp"
安卓:layout_marginTop="20dp"
安卓:layout_below="@+id/theme_red"
安卓:enabled="true"
安卓:focusable="false" />
<CheckBox
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:text="Material Blue"
安卓:id="@+id/theme_blue"
安卓:layout_gravity="center_horizontal"
安卓:textColor="@color/primary_material_light"
安卓:checked="true"
安卓:textStyle="bold"
安卓:textSize="15sp"
安卓:layout_below="@+id/theme_green"
安卓:layout_marginTop="20dp"
安卓:enabled="true" />
<CheckBox
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:text="Material Violet"
安卓:id="@+id/theme_purple"
安卓:layout_gravity="center_horizontal"
安卓:textColor="@color/primary_material_light"
安卓:checked="false"
安卓:textStyle="bold"
安卓:textSize="15sp"
安卓:layout_below="@+id/theme_blue"
安卓:layout_marginTop="20dp"
安卓:enabled="true"
安卓:focusable="false" />
</RelativeLayout>
那么,基本上,我怎么能让它显示我的弹出窗口,然后在选中复选框后关闭它呢
共 (0) 个答案