2010-08-20 45 views
5

Tôi muốn sử dụng FastScroll cho danh sách lịch sử của mình và sử dụng ngày cho các mục, nhưng hộp thoại cảnh báo (hiển thị chữ cái trong danh bạ) không kéo dài để vừa với kích thước của văn bản.Thay đổi kích cỡ hộp thoại cảnh báo FastScroll

Tôi làm cách nào để thay đổi kích thước?

+0

Mọi tiến trình? Bạn đã thử đề xuất của tôi chưa? – gary

Trả lời

1

Giải pháp của tôi. Chúng tôi vô hiệu hóa tính năng Fastscroll tích hợp và sử dụng mã this với các thay đổi nhỏ. Biến mOverlaySize chịu trách nhiệm về kích thước của cảnh báo phần.

1

Có thể đơn giản là sử dụng setView trong lớp AlertDialog không? (Cùng với một số chỉnh sửa cho .xml). Trước tiên, tôi đã lấy thông tin trên setView từ here.

public void setView (View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight, int viewSpacingBottom) 

Set the view to display in that dialog, specifying the spacing to appear around that view.  
Parameters: 
view The view to show in the content area of the dialog 
viewSpacingLeft Extra space to appear to the left of view 
viewSpacingTop Extra space to appear above view 
viewSpacingRight Extra space to appear to the right of view 
viewSpacingBottom Extra space to appear below view 

Và đây là một số mã mẫu của SDK (AlertDialogSamples.java) sử dụng setView.

case DIALOG_TEXT_ENTRY: 
      // This example shows how to add a custom layout to an AlertDialog 
      LayoutInflater factory = LayoutInflater.from(this); 
      final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null); 
      return new AlertDialog.Builder(AlertDialogSamples.this) 
       .setIcon(R.drawable.alert_dialog_icon) 
       .setTitle(R.string.alert_dialog_text_entry) 
       .setView(textEntryView) 
       .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 

         /* User clicked OK so do some stuff */ 
        } 
       }) 
       .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 

         /* User clicked cancel so do some stuff */ 
        } 
       }) 
       .create(); 
     } 
     return null; 

Và cuối cùng, một số tệp xml trông giống như nó thêm lề xung quanh văn bản (alert_dialog_text_entry.xml).

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/username_view" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_marginLeft="20dip" 
     android:layout_marginRight="20dip" 
     android:text="@string/alert_dialog_username" 
     android:gravity="left" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

Hy vọng điều đó sẽ hữu ích.

+0

Làm cách nào để áp dụng cho FastScroll? Xin lỗi vì trả lời muộn. –

Các vấn đề liên quan