2016-01-13 52 views
-6

我试图创建一个弹出窗口,其中有几个RelativeLayout,几个TextView和一个单一的ButtonAndroid - 弹出式窗口创建和样式

这里的弹出窗口:

<?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); 

Popup Image

这是我想要的弹出窗口。灰色的是弹出窗口,其中包含两个TextViews和一个Button

管理使用此tutorial创建弹出窗口。但是,还有周围的弹出窗口黑色背景像这个

Black popup

下面是onclickTextView

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

你的代码和logcat的是必须在一个回答.. – SSH

+0

烨加入它,忘记它添加 –

+0

你试图让父RelativeLayout的背景作为透明? – Nilabja

回答

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(); 
} 
+0

对不起,这是'Dialog'?我需要'PopupWindow' .. AlertDialog可以像PopupWindow一样使用吗? –

+0

它也可以作为弹出窗口使用,你可以发布你实际想要实现的图形表示吗?那肯定会帮助我们想象你的要求 – Nilabja

+0

我已经在原始代码中添加了图形表示。 –