2014-02-20 29 views
0

在我的應用程序中,我想創建一個帶有選項卡布局的警告框。 是否可以在警報框中創建一個選項卡布局? 請幫我一把。給出一個合適的解決方案。 在此先感謝!在警告框中創建一個tablayout

+0

你試過什麼? –

+0

我想在警告框中的多個選項卡中顯示內容。 – user2603471

+0

您可以爲其定製佈局並在AlertDialog中膨脹。 – Piyush

回答

0

您可以創建自定義警報對話框。

final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.YOURDIALOGTHEME)); 
    alertDialogBuilder.setCancelable(false); 
    alertDialogBuilder.setTitle(title); 
    alertDialogBuilder.setMessage(message); 
    LayoutInflater factory = LayoutInflater.from(this); 
    final View alertView = factory.inflate(R.layout.mycustomtabinalert, null); 
    alertDialogBuilder.setView(alertView); 

mycustomtabinalert.xml是佈局文件,您可以在其中創建選項卡布局。

分配正面和負面的按鈕,按要求您警告對話框

alertDialogBuilder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { 

     @Override 
     public void onClick(DialogInterface dialog, int id) { 
     } 
} 

要創建標籤,請參考文章here

1

您可以創建表格佈局的XML像你想要的。下面有來自here

<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:shrinkColumns="*" android:stretchColumns="*" android:background="#ffffff"> 
    <!-- Row 1 with single column --> 
    <TableRow 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:gravity="center_horizontal"> 
     <TextView 
      android:layout_width="match_parent" android:layout_height="wrap_content" 
      android:textSize="18dp" android:text="Row 1" android:layout_span="3" 
      android:padding="18dip" android:background="#b0b0b0" 
      android:textColor="#000"/> 
    </TableRow> 

    <!-- Row 2 with 3 columns --> 
    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"> 
     <TextView 
      android:id="@+id/TextView04" android:text="Row 2 column 1" 
      android:layout_weight="1" android:background="#dcdcdc" 
      android:textColor="#000000" 
      android:padding="20dip" android:gravity="center"/> 
     <TextView 
      android:id="@+id/TextView04" android:text="Row 2 column 2" 
      android:layout_weight="1" android:background="#d3d3d3" 
      android:textColor="#000000" 
      android:padding="20dip" android:gravity="center"/> 
     <TextView 
      android:id="@+id/TextView04" android:text="Row 2 column 3" 
      android:layout_weight="1" android:background="#cac9c9" 
      android:textColor="#000000" 
      android:padding="20dip" android:gravity="center"/> 
    </TableRow> 

    <!-- Row 3 with 2 columns --> 
    <TableRow 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:gravity="center_horizontal"> 
     <TextView 
      android:id="@+id/TextView04" android:text="Row 3 column 1" 
      android:layout_weight="1" android:background="#b0b0b0" 
      android:textColor="#000000" 
      android:padding="20dip" android:gravity="center"/> 

     <TextView 
      android:id="@+id/TextView04" android:text="Row 3 column 2" 
      android:layout_weight="1" android:background="#a09f9f" 
      android:textColor="#000000" 
      android:padding="20dip" android:gravity="center"/> 
    </TableRow> 

</TableLayout> 

表格佈局的一個例子,你可以擡高這個XML到您的警告對話框。

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(this,  R.style.anyOfYourDialogTheme)); 
alertDialogBuilder.setCancelable(false); 
alertDialogBuilder.setTitle(title); 
alertDialogBuilder.setMessage(message); 
LayoutInflater mFactory = LayoutInflater.from(this); 
View mView = mFactory.inflate(R.layout.CustomTableLayout, null); 
alertDialogBuilder.setView(mView); 

請檢查出來,讓我知道結果。

謝謝