以下screenshor是我的项目的一部分,灰色列表我使用listview而不是popupwindow
。 但我想要实现像popupwindow
这样的效果,当我点击popupwindow的外部部分时,弹出窗口就会消失。 我怎样才能点击小部件的外部和小部件解雇?
我能为做,请教我,谢谢先进
以下screenshor是我的项目的一部分,灰色列表我使用listview而不是popupwindow
。 但我想要实现像popupwindow
这样的效果,当我点击popupwindow的外部部分时,弹出窗口就会消失。 我怎样才能点击小部件的外部和小部件解雇?
我能为做,请教我,谢谢先进
如果使容器为红色区域布局,如LinearLayout
或RelativeLayout
填满屏幕,然后你可以把它点击通过XML或以编程方式捕获点击。 Here是如何做到这一点的快速例子。
这假设你只是想解雇,如果白色区域被点击。
更新:下面是一个简单的例子。这个小应用程序会将白色区域设置为红色,如果它被点击。在点击监听器中,您可以轻松地完成您需要的任务来消除红色区域。
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<!--Set onClick and clickable here to capture clicks. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/backgroundLayout"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:clickable="true"
android:onClick="layoutClicked"
tools:context="com.example.layout2.MainActivity">
<!--Set clickable here, too, to capture clicks so they don't propagate
to underlying view. The button is still enabled, though. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@android:color/holo_blue_bright"
android:clickable="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</LinearLayout>
而且支持代码:
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void layoutClicked(View view) {
// Set the background color of the "outside" area to red.
// This is where you would dismiss the red area.
view.setBackgroundColor(0xFFDD0000);
}
}
你想,当用户点击下方的红色标记的区域显示一个弹出
你的意思是添加可点击红色区域父组?我添加,它不wor,我想单击白色部分和红色区域dismiss –
@Jsonzhang查看更新的答案。 – Cheticamp
我尝试了,只有我点击顶部,红色区域才会消失,并且我点击红色区域的后面,它不会消除 –
。 – Aditya
不,我想知道如何使红色解雇,当我点击红色的外部部分 –