问题:项目中需要用ProgressDialog,不要标题,只要转动的圈和文字,但是文字不能太长,如果太长会导致整个ProgressDialog高度不断跳动。
解决:如果能得到ProgressDialog中的TextView的引用即可,搜索SDK_R10\platforms\android-12\data\res\layout,找到progress_dialog.xml文件,如下:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/body"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:paddingLeft="8dip"
android:paddingTop="10dip"
android:paddingRight="8dip"
android:paddingBottom="10dip">
<ProgressBar android:id="@android:id/progress"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="10000"
android:layout_marginRight="12dip" />
<TextView android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
</FrameLayout>
蓝色的就是我们需要引用的TextView的id,最终代码:
public void adjustProgressDialog( ProgressDialog dialog ) throws Exception
{
if( dialog == null ){ Log.e( /*TAG, "ProgressDialog is null"*/ ); return; }
//dialog.setTitle( null );
//dialog.setProgressStyle( ProgressDialog.STYLE_SPINNER );
TextView view = (TextView)dialog.findViewById( android.R.id.message );
view.setGravity( Gravity.CENTER_VERTICAL );
view.setLines( 3 ); view.setEllipsize( TruncateAt.MIDDLE );
}
注意:此调用必须在activity.showDialog()后面,或者说必须在progressDialog.show()后面调用。
我们这儿设置成只显示三行文字,而view.setEllipsize( TruncateAt.MIDDLE )的作用是当文字超过三行时,切断中间的文字来适应三行。