2016-12-16 7 views
0

이것은 안드로이드에 사용자 지정 대화 상자를 표시하는 코드입니다.안드로이드에서 가로로 중앙에서 대화 상자의 제목을 설정하는 방법

private void showCouponCodeDialog() { 

    final Dialog dialog = new Dialog(this); 
    dialog.setContentView(R.layout.dialoge_apply_coupon); 
    dialog.setTitle(R.string.apply_coupon); 

    final ProgressBar progressBar =(ProgressBar) dialog.findViewById(R.id.progressBar); 

    Button btnApplyCoupon = (Button) dialog.findViewById(R.id.btnApplyCoupon); 
    btnApplyCoupon.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      progressBar.setVisibility(View.VISIBLE); 
     } 
    }); 
    dialog.show(); 
} 

가로로 대화 상자의 제목을 설정하는 방법은 무엇입니까?

정상적인

설정하거나 사용자 정의 제목으로 대화

Dialog pauseDialog = new Dialog(this, R.style.PauseDialog); 

할 다른 것들에 스타일을 지정하는 특정 일

<?xml version="1.0" encoding="utf-8"?> 
    <resources> 
     <style name="PauseDialog" parent="@android:style/Theme.Dialog"> 
      <item name="android:windowTitleStyle">@style/PauseDialogTitle</item> 
     </style> 

     <style name="PauseDialogTitle" parent="@android:style/TextAppearance.DialogWindowTitle"> 
      <item name="android:gravity">center_horizontal</item> 
     </style> 
     <style name="DialogWindowTitle"> 
     <item name="android:maxLines">1</item> 
     <item name="android:scrollHorizontally">true</item> 
     <item name="android:textAppearance">@android:style/TextAppearance.DialogWindowTitle</item> 
     </style> 
    </resources> 

에 원하는

답변

0

는 사용자 정의 스타일 설정 중력을 설정 수동으로

// Creating the AlertDialog with a custom xml layout (you can still use the default Android version) 
AlertDialog.Builder builder = new AlertDialog.Builder(this); 
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.viewname, null); 
builder.setView(view); 

TextView title = new TextView(this); 
// You Can Customise your Title here 
title.setText("Custom Centered Title"); 
title.setBackgroundColor(Color.DKGRAY); 
title.setPadding(10, 10, 10, 10); 
title.setGravity(Gravity.CENTER); 
title.setTextColor(Color.WHITE); 
title.setTextSize(20); 

builder.setCustomTitle(title);