2016-01-13 55 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

我已經在原始代碼中添加了圖形表示。 –