Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8671329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:55:25+00:00 2026-06-12T18:55:25+00:00

In order to show dialogs with rich content and input elements, I use Android’s

  • 0

In order to show dialogs with rich content and input elements, I use Android’s AlertDialog.Builder to create an object of AlertDialog and then I use the system’s LayoutInflater to set the content (setView(...)) to some XML layout file.

This looks perfect on Android 2.X (dark background, white text):

enter image description here

But on Android 4.X it is not readable at all:

enter image description here

Note: These dialogs are not the same, of course, but the problem occurs for both dialogs.

So what am I doing wrong? I’m using Theme.Light on API level < 11 and Theme.Holo.Light on >= 11.

Edit 1: And this is the code I use for inflating:

private LayoutInflater mGlobalInflater; // in Activity class
mGlobalInflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE); // in Activity's onCreate()
mGlobalInflater.inflate(R.layout.input_dialog, null); // when needed

Edit 2: And here’s the inflated XML for the “choose date” view:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="15dp">
    <DatePicker
        android:id="@+id/input_date"
        android:startYear="1900"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:text="@string/hint" />
</LinearLayout>

Edit 3: As I found out now, the inflated dialog content is rendered correctly on Android <= 2.3.3 when using mGlobalInflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE); and it is rendered correctly on Android >= 3.0 when using mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);. So the Context makes the difference. Why?

Edit 4:

The dialog is created and inflated inside of onContextItemSelected() of Activity:

AlertDialog.Builder dialogPoup = new AlertDialog.Builder(MainActivity.this);
dialogPoup.setTitle("abc123");
final View inputDialog = mGlobalInflater.inflate(R.layout.input_dialog, null);
// setting some properties of the view and its child views
dialogPoup.setView(inputDialog);

Is this correct? Or do I have to replace MainActivity.this by a variable mContext (for example) that the Activity‘s context was assigned to in onCreate()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:55:27+00:00Added an answer on June 12, 2026 at 6:55 pm

    The only working solution that I’ve found is the following:

        LayoutInflater mInflater, mGlobalInflater;
        mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        if (android.os.Build.VERSION.SDK_INT >= 11) {
            mGlobalInflater = mInflater;
        }
        else {
            mGlobalInflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
        }
    

    Now you can use mInflater for normal inflating (such as: rows inside a ListView) and mGlobalInflater for inflating views inside of an AlertDialog (using setView()). This will then work across all API levels.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In order to show an object on a toolbox and allow user to drag/drop
In order to show the input field for a cc: adress I am trying
I created two arrays. First the arrays show the elements with no order whatsoever.
I am opening an AlertDialog to present the user a text input in order
In listening for key events in ActionBarSherlock in order to show the overflow menu
I am using simple order by clause to show products according to available quantity
order by in query is taking to much time in MySQL. SHOW PROFILES shows
Order props: Object selectedItems: Array[1] 0: SelectedItem length: 1 __proto__: Array[0] __proto__: Order I
in order to recover data from server I use XMLHttpRequest and my code is
I want to parse the below given data using resultsRequestSOAP object in order to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.