2016-09-24 67 views
0

需要幫助的我想有這樣的在調整對話框佈局

Desired dialog look

這一個自定義對話框是什麼,我都試過

enter image description here

有中沒有listView顯示我的dialog, only editText

代碼

@Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
      case R.id.action_add_task: 
       AlertDialog.Builder dialog= new AlertDialog.Builder(this); 
       LayoutInflater inflater = getLayoutInflater(); 
       View convertView = (View) inflater.inflate(R.layout.custom_dialog, null); 
       dialog.setView(convertView); 
       ListView lv = (ListView) convertView.findViewById(R.id.listView1); 
       ArrayList<ToDoList> search = new ArrayList<>(); 
       search.add(0,new ToDoList("")); //populate your list here 
       DialogAdapter adapter=new DialogAdapter(this,search,lv); 
       lv.setAdapter(adapter); 
       dialog.show(); 
       return true; 

      default: 
       return super.onOptionsItemSelected(item); 
     } 
    } 

CUSTOM_DIALOG

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/listView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

</ListView> 

dialog_with_edittext

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/img" 
     android:layout_width="35dp" 
     android:layout_height="35dp" 
     android:src="@mipmap/add_new_task" 
     android:layout_marginLeft="13dp"/> 

    <EditText 
     android:id="@+id/edtText" 
     android:layout_marginLeft="70dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="Add a new task"/> 

    <ImageView 
     android:id="@+id/dateImg" 
     android:layout_width="35dp" 
     android:layout_height="35dp" 
     android:src="@mipmap/imgdate" 
     android:layout_below="@+id/edtText" 
     android:layout_marginLeft="13dp"/> 

    <EditText 
     android:id="@+id/date" 
     android:layout_marginLeft="70dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/edtText" 
     android:hint="Date"/> 

    <ImageView 
     android:id="@+id/timeImg" 
     android:layout_width="35dp" 
     android:layout_height="35dp" 
     android:src="@mipmap/imgtime" 
     android:layout_below="@+id/date" 
     android:layout_marginLeft="13dp"/> 

    <EditText 
     android:id="@+id/time" 
     android:layout_marginLeft="70dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/date" 
     android:hint="Date"/> 

    <Button 
     android:id="@+id/cancelBtn" 
     android:background="@color/red" 
     android:textColor="@color/white" 
     android:text="Cancel" 
     android:layout_width="165dp" 
     android:layout_height="40dp" 
     android:layout_below="@+id/time" 
     android:layout_marginLeft="13dp"/> 

    <Button 
     android:id="@+id/okBtn" 
     android:background="@color/light_sky_blue" 
     android:textColor="@color/white" 
     android:text="Save" 
     android:layout_width="165dp" 
     android:layout_height="40dp" 
     android:layout_below="@+id/time" 
     android:layout_marginLeft="200dp"/> 


</RelativeLayout> 
+0

你想調整對話框中的按鈕和分隔線消失嗎? –

+0

我想在我發送的鏈接的對話框中顯示listview。 –

+0

檢查出我的答案,然後我編碼爲您的要求。 –

回答

0
  1. 將EditText的背景設置爲android:color/transparent或白色。這將從EditText刪除行,這樣就可以有一個通用的線(分割)
  2. 添加此,無論你想分頻器

    <View 
         android:layout_width="match_parent" 
         android:layout_height="1dp" 
         android:background="#aa121212" /> 
    
+0

你的意思是我用視圖而不是listview? –

+0

理想情況下,您必須使用listview。但你粗體寫道,你不想列表視圖。所以這是解決方案。 –

+0

我希望listview在對話框中顯示完全像我發送的鏈接。 –

0

嘗試dialog_with_edittext.xml此代碼。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linear" 
     android:orientation="vertical"> 
    <EditText 
     android:id="@+id/edtText" 
     android:layout_marginLeft="70dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:drawableLeft="@mipmap/add_new_task" 
     android:hint="Add a new task"/> 

    <EditText 
     android:id="@+id/date" 
     android:layout_marginLeft="70dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/edtText" 
     android:drawableLeft="@mipmap/imgdate" 
     android:hint="Date"/> 

    <EditText 
     android:id="@+id/time" 
     android:layout_marginLeft="70dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/date" 
     android:drawableLeft="@mipmap/imgtime" 
     android:hint="Date"/> 
    </LinearLayout> 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_below="@+id/linear" 
    android:layout_height="wrap_content"> 
    <Button 
     android:id="@+id/cancelBtn" 
     android:background="@color/red" 
     android:textColor="@color/white" 
     android:text="Cancel" 
     android:layout_width="wrap_content" 
     android:layout_weight="1" 
     android:layout_height="40dp" /> 

    <Button 
     android:id="@+id/okBtn" 
     android:background="@color/light_sky_blue" 
     android:textColor="@color/white" 
     android:text="Save" 
     android:layout_weight="1" 
     android:layout_width="wrap_content" 
     android:layout_height="40dp" /> 

</LinearLayout> 
</RelativeLayout> 

和消失列表視圖的分隔線使用此..

android:divider="@null". 

,或者你可以設置顏色爲分隔線。

android:divider="#FFCC00" 
+0

我應該在哪裏添加'android:divider =「@ null」。? –