我正在尝试在我的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的新手 提前致谢
答案 0 :(得分:1)
您现有的应用程序使用Theme.Black
,这就是对话框为黑色背景的原因。将主题更改为Theme.Holo.Light
以修复它。
有关建议的方法,请查看我的other answer。
编辑:您似乎正在将<application>
标记应用于正确的主题,但是您可以通过设置Theme.NoTitleBar
(它是...的后代)来覆盖它Theme.Black
)您的每项活动。
从android:theme
标记中删除<activity>
属性,它会起作用。
如果您要删除标题和操作栏,请将windowNoTitle
和windowActionBar
属性应用于主题定义:
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
答案 1 :(得分:0)
如果您想使用Holo Theme,您必须将API级别设置为14(默认情况下启用硬件加速);
尝试插入:
<uses-sdk android:minSdkVersion="14" />
在您的AndroidManifest.xml。