2017-03-08 1 views
0

모든 디바이스에서 progressDar 내에서 progressBar의 위치가 다릅니다. 그래서 그것을 사용자 정의해야합니다.사용자 정의 progressDialog를 작성하는 방법

내가 이렇게 할 때 :

public class CustomProgressDialog extends ProgressDialog { 

    public CustomProgressDialog(Context context) { 
     super(context); 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.progress_fragment_dialog); 
    } 
    } 


<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ProgressBar 
     android:layout_width="wrap_content" 
     android:layout_gravity="center" 
     android:background="@color/colorPrimary" 
     android:layout_height="match_parent" 
     android:id="@+id/progressBar" /> 

</LinearLayout> 

이 진행 대화 상자는 대화하지 않고 단지의 ProgressBar를 보여줍니다. 하지만 대화가 필요합니다.

+0

http://islandofatlas.net/2014/03/29/android-custom-progress-dialog.html, 그 I를 뜻 –

답변

2

다른 장치와의 일관성을 위해 진행률 표시 줄이있는 사용자 지정 대화 상자를 만듭니다.

final Dialog dialog = new Dialog(context); 
dialog.setContentView(R.layout.custom); 
dialog.setTitle("Title..."); 

// set the custom dialog components - title, ProgressBar and button 
TextView text = (TextView) dialog.findViewById(R.id.text); 
text.setText("COUSTOM PROGRESS TITLE"); 
ProgressBar prog = (ProgressBar) dialog.findViewById(R.id.myprogress); 
prog.setVisibilty(VISIBLE); 

Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK); 
    // if button is clicked, close the custom dialog 
    dialogButton.setOnClickListener(new OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     dialog.dismiss(); 
    } 
}); 

dialog.show(); 

레이아웃 :

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

    <ProgressBar 
     android:id="@+id/myprogress" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimary" 
     android:layout_marginRight="5dp" /> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textColor="#FFF" 
     android:layout_toRightOf="@+id/image"/>/> 

    <Button 
     android:id="@+id/dialogButtonOK" 
     android:layout_width="100px" 
     android:layout_height="wrap_content" 
     android:text=" Ok " 
     android:layout_marginTop="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_below="@+id/myprogress" 
     /> 

</RelativeLayout> 
+0

가 수행이 링크를 시도하십시오 Dialog를 확장하는 클래스를 생성 할 필요가 없다. 그러나 Progress Dialog를 사용하고자 할 때마다 그렇게 많은 코드가 있습니다! –

+0

당신이 그것을 어떻게 다룰 지 알고 있다면 그렇게 할 수 있습니다. 그렇지 않으면 이것으로 같은 것을 할 수 있습니다. –

관련 문제