2013-07-28 59 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中。