我正在尝试在我的 android 应用程序中创建一个带有加载符号的新警报框。工作正常。下面是我的代码。
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
builder.setView(inflater.inflate(R.layout.custom, null));
progress = new ProgressBar(this);
builder.setMessage("Message");
builder.setView(progress);
//builder.setCancelable(false);
builder.create().show();
我的 Custom.XML 看起来像
<?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"
android:background="#ffffff" >
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"/>
</RelativeLayout>
我的 res/styles.xml 是
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="maxWid">
<item name="android:textColor">#000000</item>
<item name="android:layout_marginTop">50dp</item>
<item name="android:layout_marginBottom">50dp</item>
<item name="android:layout_marginLeft">10dp</item>
</style>
<style name="apBtn">
<item name="android:textColor">#000</item>
<item name="android:layout_alignParentLeft">true</item>
</style>
</resources>
res/values-v11/styles.xml 是
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
res/values-v14/styles.xml 是
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
我的 AndroidManifest.cml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.kmc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="com.myapp.kmc.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.kmc.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.myapp.kmc.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.myapp.kmc.LoginActivity"
android:label="@string/title_activity_login"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:name="com.myapp.kmc.ListActivity"
android:label="@string/title_activity_list"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:name="com.myapp.kmc.CompleteActivity"
android:label="@string/title_activity_complete"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.myapp.kmc" />
</intent-filter>
</receiver>
<service android:name="com.myapp.kmc.GCMIntentService" />
<activity
android:name="com.myapp.kmc.RegisterDevice"
android:theme="@android:style/Theme.NoTitleBar"
android:label="@string/title_activity_register_device" >
</activity>
</application>
</manifest>
在 android 4.1.2 中测试
但是,当我创建一个新应用程序并遵循此代码时,我会收到一个像这样的警报框
但是当我在现有应用程序中实现相同的代码时。我收到这样的警报框
因为我想要现有应用程序中的第一个。它毁了我的时间..
谁能帮帮我吗。我是android新手提前谢谢