2015-02-11 55 views
0

是否可以使用自定義格式創建對話框?我的意思是,不是一個方形對話框,而是一個奇怪的格式。在android上創建自定義格式的對話框

Here's的我想要的東西的圖片: http://s3.postimg.org/ha5g0d437/popup_chat.png

我想這是一個對話框,我的Android應用程序,就像一個彈出窗口。是否有可能給他這種奇怪的格式ou我必須使用正方形?

+0

你喜歡它像泡泡聊天權嗎? – 2015-02-11 23:38:46

+0

泡沫?你的意思是像一個彈出?如果它是一個彈出窗口,那麼是的 – user3713134 2015-02-11 23:40:43

回答

0

您可以在佈局文件夾中爲對話框佈局創建xml文件。說你的名字dialog.xml,你可以在那裏添加圖片和按鈕。然後在您的主要活動的java:

 final Dialog myDialog = new Dialog(MainActivity.this); 
     myDialog .setTitle("My fancy dialog"); 
     myDialog .setContentView(R.layout.dailog); 
     Button meBtn = (Button) dealerDialogDialog.findViewById(R.id.newBtn); 
     meBtn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       //do something or just: 
       myDialog.cancel(); 
      } 
     }); 
     myDialog.show(); 

我希望這可以幫助您

2

你可以嘗試創建你需要例如添加圖像彈出作爲背景,然後添加你需要的EditText佈局的佈局設計,使用此代碼添加您的佈局..

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder (this); 

LayoutInflater inflater = this.getLayoutInflater(); 
View dialogView = inflater.inflate (R.layout.YOUR_LAYOUT, null); 
dialogBuilder.setView (dialogView); 

EditText EditText = (EditText) dialogView.findViewById (R.id.label_field); 
editText.setText ("test label"); 
AlertDialog dialogBuilder.create alertDialog =(); 
alertDialog.show();