我尝试了以下代码来创建自定义进度对话框。但我没有得到想要的输出。
以下是我的 MainActivity.java 代码
public class MainActivity extends Activity {
private ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected Dialog onCreateDialog(int id) {
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setIcon(R.drawable.alert_dialog_icon);
mProgressDialog.setTitle(R.string.select_dialog);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
return mProgressDialog;
} }
strings.xml 文件如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="select_dialog">Sample</string>
<string name="select_dialog_show">List dialog</string>
<string name="app_name">Dialog</string>
</resources>
activity_main.xml 如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
</RelativeLayout>
DialogManifest.xml 如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.dialog"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="1"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.sample.dialog.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>