代码之家  ›  专栏  ›  技术社区  ›  Yeahia2508

更改Unicode中的ProgressDialog进度号

  •  2
  • Yeahia2508  · 技术社区  · 7 年前

    要设置当前进度,我正在使用set progress方法。这是以英文数字显示当前进度,但我想将此进度更改为孟加拉语。如何将此进度号从英语更改为孟加拉语?

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  1
  •   Jantzilla    7 年前

    因为 ProgressDialog 不推荐使用,您应该使用 ProgressBar 相反。

    使用此方法可以创建一个简单的 进度条 随着 TextView 百分比和部分进度的指标。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">
    
    <ProgressBar
        android:id="@+id/determinateBar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_centerInParent="true"
        style="@android:style/Widget.Holo.Light.ProgressBar.Horizontal" />
    
    <TextView
        android:id="@+id/tv_percent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="10"
        android:layout_below="@id/determinateBar"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true" />
    
    <TextView
        android:id="@+id/tv_fraction"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="10/100"
        android:layout_below="@id/determinateBar"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true" />
    
    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/tv_fraction"
        android:layout_centerInParent="true"
        android:text="Run" />
    
    </RelativeLayout>
    

    然后创建要使用的值的自定义资源字符串数组。

    <resources>
    <string-array name="numbers">
        <item>  ০   </item>
        <item>  à§§   </item>
        <item>  ২   </item>
        <item>  à§©   </item>
        <item>  ৪   </item>
        <item>  à§«   </item>
        <item>  ৬   </item>
        <item>  à§­   </item>
        <item>  à§®   </item>
        <item>  ৯   </item>
        <item>  ১০  </item>
        <item>  à§§à§§  </item>
        <item>  ১২  </item>
        <item>  à§§à§©  </item>
        <item>  ১৪  </item>
        <item>  à§§à§«  </item>
        <item>  ১৬  </item>
        <item>  à§§à§­  </item>
        <item>  à§§à§®  </item>
        <item>  ১৯  </item>
        <item>  ২০  </item>
        <item>  ২১  </item>
        <item>  ২২  </item>
        <item>  ২৩  </item>
        <item>  ২৪  </item>
        <item>  ২৫  </item>
        <item>  ২৬  </item>
        <item>  ২৭  </item>
        <item>  ২৮  </item>
        <item>  ২৯  </item>
        <item>  ৩০  </item>
        <item>  à§©à§§  </item>
        <item>  ৩২  </item>
        <item>  à§©à§©  </item>
        <item>  ৩৪  </item>
        <item>  à§©à§«  </item>
        <item>  ৩৬  </item>
        <item>  à§©à§­  </item>
        <item>  à§©à§®  </item>
        <item>  ৩৯  </item>
        <item>  ৪০  </item>
        <item>  ৪১  </item>
        <item>  ৪২  </item>
        <item>  ৪৩  </item>
        <item>  ৪৪  </item>
        <item>  ৪৫  </item>
        <item>  ৪৬  </item>
        <item>  ৪৭  </item>
        <item>  ৪৮  </item>
        <item>  ৪৯  </item>
        <item>  ৫০  </item>
        <item>  ০   </item>             <!-- TODO Complete array -->
        <item>  à§§   </item>
        <item>  ২   </item>
        <item>  à§©   </item>
        <item>  ৪   </item>
        <item>  à§«   </item>
        <item>  ৬   </item>
        <item>  à§­   </item>
        <item>  à§®   </item>
        <item>  ৯   </item>
        <item>  ১০  </item>
        <item>  à§§à§§  </item>
        <item>  ১২  </item>
        <item>  à§§à§©  </item>
        <item>  ১৪  </item>
        <item>  à§§à§«  </item>
        <item>  ১৬  </item>
        <item>  à§§à§­  </item>
        <item>  à§§à§®  </item>
        <item>  ১৯  </item>
        <item>  ২০  </item>
        <item>  ২১  </item>
        <item>  ২২  </item>
        <item>  ২৩  </item>
        <item>  ২৪  </item>
        <item>  ২৫  </item>
        <item>  ২৬  </item>
        <item>  ২৭  </item>
        <item>  ২৮  </item>
        <item>  ২৯  </item>
        <item>  ৩০  </item>
        <item>  à§©à§§  </item>
        <item>  ৩২  </item>
        <item>  à§©à§©  </item>
        <item>  ৩৪  </item>
        <item>  à§©à§«  </item>
        <item>  ৩৬  </item>
        <item>  à§©à§­  </item>
        <item>  à§©à§®  </item>
        <item>  ৩৯  </item>
        <item>  ৪০  </item>
        <item>  ৪১  </item>
        <item>  ৪২  </item>
        <item>  ৪৩  </item>
        <item>  ৪৪  </item>
        <item>  ৪৫  </item>
        <item>  ৪৬  </item>
        <item>  ৪৭  </item>
        <item>  ৪৮  </item>
        <item>  ৪৯  </item>
        <item>  ৫০  </item>
    </string-array>
    

    接下来,在你的活动中使用这个数组相对于你的操作。

    public class MainActivity extends Activity {
    private int progressStatus = 0;
    private Handler handler = new Handler();
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        final Button btn = (Button) findViewById(R.id.btn);
        ProgressBar progressBar = (ProgressBar) findViewById(R.id.determinateBar);
        TextView percent = (TextView) findViewById(R.id.tv_percent);
        TextView fraction = (TextView) findViewById(R.id.tv_fraction);
    
        String[] numbers = getResources().getStringArray(R.array.numbers);
    
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // Set the progress status zero on each button click
                progressStatus = 0;
    
                // Start the lengthy operation in a background thread
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        while(progressStatus < 100){
                            // Update the progress status
                            progressStatus +=1;
    
                            // Try to sleep the thread for 20 milliseconds
                            try{
                                Thread.sleep(20);
                            }catch(InterruptedException e){
                                e.printStackTrace();
                            }
    
                            // Update the progress bar
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    pb.setProgress(progressStatus);
                                    // Show the progress on TextView
                                    percent.setText(numbers[progressStatus]);
                                    fraction.setText(numbers[progressStatus] + "/১০০");
                                }
                            });
                        }
                    }
                }).start(); // Start the operation
           }
        });
      }
    }