【发布时间】:2016-01-13 05:18:26
【问题描述】:
我正在尝试创建一个弹出窗口,其中包含多个RelativeLayout、多个TextView 和一个Button。
这是弹出窗口:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_handphone_MainLayout"
android:layout_width="match_parent" android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/popup_handphone_Wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/popup_handphone_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/popupPhoneMessage"/>
<RelativeLayout
android:id="@+id/popup_handphone_functionalities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/popup_handphone_text"
android:layout_marginTop="15dp">
<EditText
android:id="@+id/popup_handphone_phoneNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/popup_handphone_phoneNumberConfirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/popup_handphone_phoneNumber"
android:layout_marginTop="10dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/popup_handphone_phoneNumberConfirm"
android:layout_marginTop="20dp"
android:layout_marginBottom="40dp"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
如何在Activity 上显示它?尝试使用LayoutInflater,但出现错误,提示它找到了View..
代码:
RelativeLayout mainLayout = (RelativeLayout)findViewById(R.id.popup_handphone_MainLayout);
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout popupLayoutInflater = inflater.inflate(R.layout.popup_handphone, mainLayout);
//This part here said it needs android.widget.RelativeLayout, but found android.view.View
popupLayout = (RelativeLayout)findViewById(R.layout.popup_handphone);
这是我想要的弹出窗口。灰色的是包含两个TextViews 和一个Button 的弹出窗口
设法使用此tutorial 创建一个弹出窗口。但是弹窗周围有黑色背景 像这样
这是TextView 上onclick 的更新代码
View.OnClickListener phoneReinputHandler = new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(SignupStepTwoActivity.this, PopupHandphone.class);
backDim = (RelativeLayout) findViewById(R.id.bac_dim_layout);
//backDim.setVisibility(View.VISIBLE);
startActivity(intent);
};
如何去除黑色的东西?
【问题讨论】:
-
你的代码和logcat是必须要回答的..
-
是的,添加了,忘记添加了
-
您是否尝试过将父级 relativelayout 背景设为透明?
-
是的,我试过了,似乎不是相对背景造成的。这可能是主题吗?不过,我现在正在使用
PopupWindow,正在努力通过触摸窗外来解除它 -
可能是因为他们,我从来没有在 popupwindow 上工作过所以不太确定,但是您提供的设计可以使用对话框轻松创建
标签: android