如何修复应用主题

时间:2016-09-25 12:56:59

标签: android xml android-layout

我正在开发已开发的应用程序的新版本。现在我面临这个奇怪的问题,无论我在xml中设置的背景颜色,但是当app运行时它显示深色背景,有点黑。

这是styles.xml。注意colorPrimary,colorPrimaryDark,colorAccent是绿色的。

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="MyTheme" parent="android:Theme.Holo.Light.Dialog">
        <!--<item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
        <item name="android:windowBackground">@color/transparent</item>
        <!--<item name="android:textColorPrimary">#FFFFFF</item>-->
        <item name="android:backgroundDimEnabled">false</item>
        <!--<item name="android:textColor">#FFFFFF</item>-->
        <!--<item name="android:textStyle">normal</item>-->
        <item name="android:textSize">12sp</item>-->
    </style>

    <style name="CustomAlertDialogStyle">
        <!--<item name="android:bottomBright">@color/transparent</item>-->
        <!--<item name="android:bottomDark">@color/transparent</item>-->
        <!--<item name="android:bottomMedium">@color/transparent</item>-->
        <!--<item name="android:centerBright">@color/transparent</item>-->
        <!--<item name="android:centerDark">@color/transparent</item>-->
        <!--<item name="android:centerMedium">@color/transparent</item>-->
        <!--<item name="android:fullBright">@color/transparent</item>-->
        <!--<item name="android:fullDark">@color/transparent</item>-->
        <!--<item name="android:topBright">@color/transparent</item>-->
        <!--<item name="android:topDark">@color/transparent</item>item-->
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

这是它的外观。基本上这是活动中的对话框。 enter image description here

以下是它应该如何而不是上面的图像。 android studio xml预览的屏幕截图 enter image description here

请帮帮我!

修改

这是xml的活动和片段

活动的xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme">

    <android.support.v7.widget.Toolbar
        android:id="@+id/consumer_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme" />
    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabGravity="fill" />
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/AppTheme"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

Fragment的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=".activities.test.OneFragment">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Text"
    android:textSize="40dp"
    android:textStyle="bold"
    android:layout_centerInParent="true"/>

  </RelativeLayout>

这里是对话的java代码。

Dialog dialog = new Dialog(this);
            dialog.setContentView(R.layout.consumer_welcome_dialogue);
            dialog.show();
            Window window = dialog.getWindow();
            window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

这是清单

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
    android:name=".AppController"
    android:allowBackup="true"
    android:icon="@drawable/ic_icon"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".updated.activities.SplashActivity"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".updated.activities.SplashSecond"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.AppCompat.NoActionBar" />
    <activity
        android:name=".updated.activities.ConsumerRetailerActivity"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.AppCompat.NoActionBar"
        android:label=" "/>
    <activity
        android:name=".updated.activities.consumer.TestLoginConsumerActivity"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.AppCompat.NoActionBar"
        android:label=" "/>
    <activity
    android:name=".updated.activities.consumer.TestSignUpConsumerActivity"
    android:label=" "
    android:theme="@style/Theme.AppCompat.NoActionBar"
    android:screenOrientation="portrait" />
    <activity
        android:name=".updated.activities.retailer.TestRetailerSignUp"
        android:label=" "
        android:theme="@style/Theme.AppCompat.NoActionBar"
        android:screenOrientation="portrait" />
    <activity
        android:name=".updated.activities.retailer.TestRetailerLoginActivity"
        android:label=" "
        android:theme="@style/Theme.AppCompat.NoActionBar"
        android:screenOrientation="portrait" />
    <activity
        android:name=".updated.activities.retailer.TestRetailerAccountActivity"
        android:label=" "
        android:theme="@style/Theme.AppCompat.NoActionBar"
        android:screenOrientation="portrait" />

    <activity
        android:name=".updated.activities.consumer.TestTabConsumerActivity"
        android:label=" "
        android:theme="@style/Theme.AppCompat.NoActionBar"
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.LoginActivity"
        android:screenOrientation="portrait"
        android:label=" "
        android:windowSoftInputMode="stateVisible" />
    <activity
        android:name=".activities.CatagActivity"
        android:label=" "
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.consumer.ConsumerHome"
        android:label=" "
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.consumer.ConsumerSignUp"
        android:label=" "
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.retailer.RetailerSignUp"
        android:label=" "
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.retailer.RetailerHomeActivity"
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.retailer.MyStoresActicity"
        android:screenOrientation="portrait"
        android:label=" "
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name=".activities.retailer.AddStoreActivity"
        android:label=" "
        android:screenOrientation="portrait" />
    <activity
        android:screenOrientation="portrait"
        android:name=".activities.retailer.StoreBranches"
        android:label=" "
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name=".activities.retailer.AddBranchActivity"
        android:label=" "
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.SettingActivity"
        android:label=" "
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.consumer.MySubscriptionsActivity"
        android:label=" "
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.consumer.AddSubscription"
        android:label=" "
        android:screenOrientation="portrait" />
    <activity
        android:name=".activities.consumer.SubscribeBranchesActivity"
        android:label=" "
        android:screenOrientation="portrait" />
    <activity
        android:screenOrientation="portrait"
        android:name=".activities.retailer.RetailerPromotionsActivity"
        android:label=" "
        android:parentActivityName=".activities.retailer.RetailerHomeActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.wisaver.app.activities.retailer.RetailerHomeActivity" />
    </activity>
    <activity android:name=".activities.consumer.Consumer_Offers"
        android:label=" "
        android:screenOrientation="portrait"/>
    <activity android:name=".activities.consumer.ConsmOffersActivity"
        android:label=" "
        android:screenOrientation="portrait"/>
    <activity android:name=".activities.OfferDetails"
        android:label=" " />
</application>

这是带有背景图片的xml预览。我只是添加backgroud="drawable/backgound" 它应该出现在这样的应用程序中,但它不显示背景,而是显示黑色背景

enter image description here

1 个答案:

答案 0 :(得分:0)

哇,没有看到有人使用Developers Tools ......

我认为您的问题是Dialog的问题。 您是否尝试将对话构造函数与Theme?一起使用?,如下所示:new AlertDialog/*.Builder*/(Context context, int theme);