H
H
HAbRAhabp2016-03-28 13:57:55
Java
HAbRAhabp, 2016-03-28 13:57:55

Incorrect styles of AlertDialog on API 18?

Subject. activity code:

package com.gobonus.gobonus;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class InternetDisabled extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_internet_disabled);

        AlertDialog.Builder builder =
                new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);

        builder.setTitle(R.string.title);
        builder.setMessage(R.string.err_503);

        builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.show();

    }
}

Manifesto:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gobonus.gobonus">

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/welcomeActivivty">
        <activity android:name=".WelcomeActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/title_activity_login"
            android:theme="@style/GB"
            android:parentActivityName=".WelcomeActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.gobonus.gobonus.WelcomeActivity" />
        </activity>
        <activity android:name=".InternetDisabled"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
        <activity
            android:name=".CabinetActivity"
            android:label="@string/title_activity_cabinet"
            android:theme="@style/GB_Green.NoActionBar" />
        <activity
            android:name=".CabinetActivityy"
            android:label="@string/title_activity_cabinet_activityy"
            android:theme="@style/GB_Green.NoActionBar"></activity>
    </application>

</manifest>

Style (without specifying the api version, lies in /values/styles.xml):
<!--alert dialog-->
        <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
            <item name="colorAccent">#FFCC00</item>
            <item name="android:textColorPrimary">#FFFFFF</item>
            <item name="android:background">#5fa3d0</item>
        </style>

There are no errors in the logs.
On API 18 (4.3) I get this ugly window:
RZ03Q.png
Everything is fine on API 22:
WoXEf.png
Why is that? And how to solve it? Tested only on API 18 and 22
Markup:
<?xml version="1.0" encoding="utf-8"?>
    <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="com.gobonus.gobonus.InternetDisabled">
    
    </RelativeLayout>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HAbRAhabp, 2016-03-28
@HAbRAhabp

Problem solved. The import came from the library import android.app.AlertDialog. It turns out that the native library was used. After replacing it, import android.support.v7.app.AlertDialog;everything worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question