2016-04-02 11 views
1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:elevation="4dp" 

    android:background="@color/colorWhite"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/add_album_title" 
     android:shadowColor="@color/colorWhite" 
     android:text="Enter the Album Name" 
     android:textSize="20sp" 
     /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/new_album_name" 
     android:textSize="25sp" 
     android:hint="Album name"/> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="2"> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:id="@+id/add_new_album_button" 
     android:text="Add" 
     android:textAllCaps="false"/> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:id="@+id/cancel_new_album_button" 
     android:text="Cancel" 
     android:textAllCaps="false"/> 
    </LinearLayout> 
</LinearLayout> 

私はレイアウトとしてこのコードを持っています。 これをアクティビティのダイアログとして設定したいと思います。しかし、私はそれを実行すると、ちょうど平野のように見える 。私は多くのスタイリング知識を持たないAndroidで初心者です。 誰かが私にダイアログボックスのスタイルを手伝ってもらえますか?Androidの完全カスタムダイアログボックス

これを実装するためのコードを示します。私はちょうどボタンをコメントしました 今私の焦点はスタイリングとそれをより魅力的にするためです。

public class AddAlbumDialog extends DialogFragment { 
    Button addButton,cancelButton; 
    EditText newAlbumName; 
    TextView title; 
    Context context; 

    public AddAlbumDialog() { 
     //Empty Constructor 
    } 



    @Override 
    public void onStart() { 
     super.onStart(); 

     Dialog dialog = getDialog(); 
     if (dialog != null) { 
      dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
      dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
      dialog.getWindow().setGravity(Gravity.CENTER); 
     } 
    } 


    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 

     // Get the layout inflater 
     LayoutInflater inflater = getActivity().getLayoutInflater(); 
     builder.setCancelable(false); 


     // Inflate and set the layout for the dialog 
     // Pass null as the parent view because its going in the dialog layout 
     builder.setView(inflater.inflate(R.layout.add_album_dialog_fragment,null)); 
       // Add action buttons 
//  .setPositiveButton(R.string.add_album, null) 
//   @Override 
//   public void onClick(DialogInterface dialog, int which) { 
//    Dialog d = (Dialog) dialog; 
// 
//    EditText newAddAlbum = (EditText) d.findViewById(R.id.new_album_name); 
//    newAddAlbum.requestFocus(); 
//    if (newAddAlbum.getText().toString().trim().isEmpty()) { 
//     Toast.makeText(getActivity(), "Empty Name Cannot Add", Toast.LENGTH_SHORT).show(); 
// 
//    } else { 
//     mListener.onDialogPositiveClick(AddAlbumDialog.this, newAddAlbum); 
//    } 
//   } 
//  }) 
       //Add Negative Button 
//  .setNegativeButton(R.string.cancel_dialog, new DialogInterface.OnClickListener() { 
//   @Override 
//   public void onClick(DialogInterface dialog, int which) { 
//    Toast.makeText(getActivity(), "Cancel Called Name", Toast.LENGTH_SHORT).show(); 
//    mListener.onDialogNegativeClick(AddAlbumDialog.this); 
//    dismiss(); 
//   } 
//  }); 




     return builder.create(); 
    } 









    /* The activity that creates an instance of this dialog fragment must 
    * implement this interface in order to receive event callbacks. 
    * Each method passes the DialogFragment in case the host needs to query it. */ 
    public interface AddAdlbumListener { 
     public void onDialogPositiveClick(DialogFragment dialog,EditText newAlbumName); 
     public void onDialogNegativeClick(DialogFragment dialog); 
    } 

    // Use this instance of the interface to deliver action events 
    AddAdlbumListener mListener; 

    // Override the Fragment.onAttach() method to instantiate the NoticeDialogListener 
    @Override 
    public void onAttach(Activity activity) { 
     super.onAttach(activity); 
     // Verify that the host activity implements the callback interface 
     try { 
      // Instantiate the NoticeDialogListener so we can send events to the host 
      mListener = (AddAdlbumListener) activity; 
     } catch (ClassCastException e) { 
      // The activity doesn't implement the interface, throw exception 
      throw new ClassCastException(activity.toString() + " must implement NoticeDialogListener"); 
     } 
    } 




} 

メインアクティビティでは、このコードを使用して表示しています。

AddAlbumDialog addAlbumDialog=new AddAlbumDialog(); 


addAlbumDialog.show(getSupportFragmentManager(),"Custom Dialog"); 

誰かが助けてくれれば非常に感謝しています。

style.xml
+0

http://www.mkyong.com/android/android-custom-dialog-example/にアクセスしてください。 –

答えて

2

あなたは良い表情でカスタマイズダイアログを作りたいなら、あなたはスタイルとあなたのダイアログのテーマを設定する必要があります。

styleは、ビューまたはウィンドウの外観と書式を指定するプロパティのコレクションです。

私はちょうどあなたが行の下で、あなたのダイアログに設定することができますスタイルのいくつかの例を掲載しています:あなたはスタイルで新しいスタイルを作成する必要が

Dialog dialog = new Dialog(YourActivity.this, R.style.MyTheme); 

style.xml

.xml:

<style name="CustomDialogTheme" parent="@android:style/Theme.Dialog"> 
    <item name="android:bottomBright">@color/white</item> 
    <item name="android:bottomDark">@color/white</item> 
    <item name="android:bottomMedium">@color/white</item> 
    <item name="android:centerBright">@color/white</item> 
    <item name="android:centerDark">@color/white</item> 
    <item name="android:centerMedium">@color/white</item> 
    <item name="android:fullBright">@color/orange</item> 
    <item name="android:fullDark">@color/orange</item> 
    <item name="android:topBright">@color/blue</item> 
    <item name="android:topDark">@color/blue</item> 
</style> 

<style name="MyTheme"> 
    <item name="android:alertDialogStyle">@style/CustomDialogTheme</item> 
</style> 

これは単なる例です。詳細を知りたい場合は、以下のリンクを参照してください。 http://blog.supenta.com/2014/07/02/how-to-style-alertdialogs-like-a-pro/

希望すると助かります。

+0

ありがとう紀州、本当に有用で迅速な返信。 –

+0

@AnandVardhan:ようこそ。 – KishuDroid

1
public void dialog() 
    { 
     final Dialog dialog = new Dialog(HomeActivity.this, R.style.cust_dialog); 
     dialog.setTitle("Select Content Language"); 

     dialog.setContentView(R.layout.add_album_dialog_fragment); 
     // dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
     dialog.setCanceledOnTouchOutside(false); 
     dialog.setCancelable(false); 

     Button button=(Button)dialog.findViewById(R.id.textView_camera); 
     button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       dialogLanguage(); 
       ll_slide.setVisibility(View.GONE); 

       dialog.dismiss(); 
      } 
     }); 

     dialog.show(); 
    } 

と設定スタイル:

<style name="cust_dialog" parent="@android:style/Theme.Dialog"> 
     <item name="android:windowTitleStyle">@style/dialog_title_style</item> 

    </style> 
    <style name="dialog_title_style" parent="android:Widget.TextView"> 
     <item name="android:background">@color/status_bar</item> 
     <item name="android:windowBackground">@android:color/transparent</item> 
     <item name="android:textColor">@color/white</item> 
     <item name="android:textSize">20sp</item> 
     <item name="android:padding">10dp</item> 
     <item name="android:gravity">center_horizontal|center_vertical</item> 
    </style> 
+0

Android Geekに感謝します。ありがとうございました。 –

+0

@AnandVardhan偉大な...これは、あなたが答えをアップアップすることができれば助け....事前に感謝:) –

関連する問題