我尝试创建一个弹出窗口,其中包含多个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管理创建弹出窗口。但弹出窗口周围有黑色背景,如此
这是onclick
TextView
的更新代码
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);
};
如何删除黑色东西?
答案 0 :(得分:0)
看到这个并根据您的需要进行修改
public void showDialog()
{
final Dialog dialog = new Dialog(mContext, android.R.style.ThemeOverlay_Material);/*choose your theme*/
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));/*choose your style*/
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);/*to remove title*/
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); //Optional
dialog.setContentView(R.layout.dialog_dash_wish);/*enter your xml layout name*/
//Any other code you want in your constructor
TextView popup_handphone_text = (TextView) dialog.findViewById(R.id.popup_handphone_text);
EditText popup_handphone_phoneNumber = (EditText) dialog.findViewById(R.id.popup_handphone_phoneNumber);
EditText popup_handphone_phoneNumberConfirm = (EditText) dialog.findViewById(R.id.popup_handphone_phoneNumberConfirm);
Button button = (Button) dialog.findViewById(R.id.bt_id);
button .setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
dialog.dismiss();
}
});
dialog.show();
}