2013-07-28 60 views
0

我想在我的android应用程序中创建一个带有加载符号的新警报箱。工作正常。以下是我的代码。不正确的主题应用于AlertDialog

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 /值-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

但是,当我创建一个新的应用程序,并按照这个代码我得到一个警告框,这样

enter image description here

但是当我在我现有的应用程序中实现相同的代码。我得到一个警告框,这样

enter image description here

因为我想在我的现有应用程序的第一个。它毁了我的时间..

任何人都可以请帮助我。我是新来的android 在此先感谢

+0

检查与Android版本,主题。第一个看起来像holo主题 – Niko

+0

你有哪些Android版本的设备? –

+0

嗨,我在Android 4.1.2检查这两个应用程序 – ramesh

回答

1

您现有的应用程序使用Theme.Black,这就是为什么对话框有黑色背景。将主题更改为Theme.Holo.Light以解决此问题。

对于推荐的方法,请看我的other answer


编辑:看起来你申请正确的主题,你的<application>标签,但此时你通过设置Theme.NoTitleBar(这是Theme.Black的后裔),您的每一个活动的覆盖它。

删除android:theme属性从<activity>标签,它会工作。 如果要删除标题和动作条,适用windowNoTitlewindowActionBar属性你的主题定义:

<item name="android:windowNoTitle">true</item> 
<item name="android:windowActionBar">false</item> 
+0

嗨感谢您的答复..我是新来的这个。从哪里我可以改变主题? – ramesh

+0

@ramesh我链接的答案详细解释了这一点。 –

+0

我试过,但没有工作。另外我的res/styles.xml已经在我的问题中更新了..你能看一下吗? – ramesh

0

如果你想使用全息主题,你必须将API级别设置为14(已硬件加速启用为默认);

尝试插入:

<uses-sdk android:minSdkVersion="14" /> 

在AndroidManifest.xml中。