Android alert dialog not styled properly on Lollipop - android

I have tried everything to get this working and cannot figure it out.
I am trying to use an alert dialog im my app. It works fine on KitKat but not on Lollipop.
I have even tried using many material dialogs on GitHub and again they work on Kitkat but not on Lollipop.
I am testing on my Nexus 5 with stock nexus factory image.
KITKAT WITH GITHUB MATERIAL DIALOG
KITKAT WITH STOCK ALERT DIALOG
LOLLIPOP WITH GITHUB MATERIAL DIALOG
LOLLIPOP WITH STOCK ALERT DIALOG
Also this is the library on github installed on the same device its not working on. So its something about my app that is causing this. what could it be

android:fitsSystemWindows="true" was the culprit.
I had that declared in my styles.xml.
Removed it from styles.xml and placed in my layout and it working now.

I had the same problem and didn't find any fitsSystemWindows on any of my styles.xml.
To solve it i had to wrap the Layout in a FrameLayout and add the margins to the Layout like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/dialog_margin_title"
android:layout_marginBottom="#dimen/dialog_margin"
android:layout_marginLeft="#dimen/dialog_margin"
android:layout_marginStart="#dimen/dialog_margin"
android:layout_marginRight="#dimen/dialog_margin"
android:layout_marginEnd="#dimen/dialog_margin"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please enter the email address of the person you would like to follow, this person will be notified." />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" />
</LinearLayout>
</FrameLayout>

Related

Popup of AutoCompleteTextView is showing behind keyboard

I have an AutoCompleteTextView in my app, at the bottom of the layout.
When user inputs data, suggestion popup with items should appear.
All works as expected on Android Samsung device with OS 6.0.1:
But for Android 8.0.0 (LG device and also an emulator 8.1.0), I don't see such popup, I suppose it showing behind keyboard for some reason (Because when I clicked back button nothing happened - popup handled that event, and only on second back click keyboard disappeared):
My AutocompleteTextview:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout ...
<android.support.v7.widget.AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="#drawable/thin_square_border"
android:maxLines="3"
android:minHeight="60sp"
android:padding="12dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:textColor="#color/charcoalgray"
/>
</LinearLayout>
</ScrollView>
I've tried dropDownAnchor on view above, and android:dropDownHeight="wrap_content" but that didn't help.
I found this solution that works for me in Oreo and Pie.
I added this to my fragment:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
This seems like a bug introduced in Oreo. Hope this helps for your case.
you have to set android:dropDownAnchor="#id/container_comment" in your autocomplete widget

Android : Cardview Background is turning to black on 4.1.2

I am using google cardView support library for my card functionality. It works well for kitkat and version up but however the background of card is set to black and padding/margins are not applied on device 4.1.2.
<android.support.v7.widget.CardView
android:id="#+id/all_goals_card_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:padding="10dp"
app:cardCornerRadius="4dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardBackgroundColor="#android:color/white"
>
</android.support.v7.widget.CardView>
Okay, I just stumbled across the same issue and I found some devices to have some "special" very-light light-theming defaults cough samsung cough I will answer this slightly old queston.
The thing here is that you are most likely using the wrong context to inflate you layout. I think you are using the application-context to do so. Application-Context does not apply the theme you defined.
This (inflating with the application-context) is legal, but inflation
will be done with the default theme for the system on which you are
running, not what’s defined in your application.*
For example if you do:
LayoutInflater.from(context).inflate(R.layout.menu_rental_list_item, parent, false);
The context here should be an Activity- or Fragment Context - NOT the application-context.
Please double check that.
*) Ah, you want to read more about contexts? Please continue reading here.
don't use "#android:color/white"
card_view:cardBackgroundColor="#fff"
This will solve the issue:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#fff"
card_view:cardBackgroundColor="#fff"
android:layout_margin="2dp">
Notice these lines:
xmlns:card_view="http://schemas.android.com/apk/res-auto"
and
card_view:cardBackgroundColor="#fff"
I had the same issue on android 4.1.2 device. I was using an ImageView with shape drawable inside CardView which was the actual culprit.
Please check the answer in this link which helped me fix the issue.
In my case, I put android:theme="#style/Theme.AppCompat.Light.NoActionBar" in the manifest file for related activity
Don't use
android:Theme.Dialog
or
android.R.style.Theme_Dialog
, if your CardView is a part of the DialogFragment or Dialog layout.

Android KitKat get Toast radius?

Im using the library by RomainNurik to show an Undo-Toast to the user (like in the Gmail app)
Prior to KitKat the toast option was rectangular, and in KitKat there toast message has rounded corners.
Is there a get() method to get the Radius of the Toast? So that if im using the library,I can getRadius() ,and adjust my toast according to that?
Note: Otherwise I would have to specify two differnt values, one prior to KitKat and one for KitKat.
Maybe what you want is android:shadowRadius of the Toast which is 2.75 in the layout file.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?android:attr/toastFrameBackground">
<TextView
android:id="#android:id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:textAppearance="#style/TextAppearance.Toast"
android:textColor="#color/bright_foreground_dark"
android:shadowColor="#BB000000"
android:shadowRadius="2.75"
/>
</LinearLayout>
I found it in Android SDK\sdk\platforms\android-19\data\res\layout named transient_notification.xml

Android text gets clipped on some devices

I am facing an issue in one phone (till yet). My app uses Hindi fonts. It shows well on emulator, tab, many other phones too. But one of the phone which I am using for testing purpose is showing the text going cut from sides.
I tried almost everything for putting it in the right order but none worked. Here posting the screenshots of two of my test phones and the text.
The screenshot with error:
The screenshot of other phones: and the expected one too:
What could be the reason and how can I solve it? Please let me know!!
TextView configs I am using:
<TextView
android:id="#+id/A_lbl_mandir"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/Abt_mandir"
android:textAlignment="center"
android:textColor="#80000A"
android:textSize="35sp" />
EDIT: My complete activity 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:id="#+id/text"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="#string/hello_world" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/text" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:padding="5sp"
android:text="#string/test"/>
</ScrollView>
</RelativeLayout>
I have tried and deleted many other things especially for this phone. But unable to solve the issue!
this occurs in 4.1.2 and its documented as a bug in Google which they have fixed in 4.2.
https://code.google.com/p/android/issues/detail?id=34432
This happens with unicode fonts where the Android OS is not able to calculate the length of the text.
try this.
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_below="#id/text"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="left"
android:padding="5sp"
android:text="#string/test"/>
</ScrollView>
All right! Found another phone with same issue. In that phone too, the text was clipped. I guess there is some problem with the phone. Because even popular apps like Whatsapp has got the same problem on that device. The Hindi text was cut same as shown in the images above.
Possible fix for that issue: (if someone gets that n what I am doing now.) I realised that browser shows the hindi fonts well on that. So better make a native app on html, javascript especially for such devices and view the HTML using WebView.The application will get a little slow but we have to do it Until we get the actual problem creating it.
Please note: this is not a solution, but a fix to make that work. Better known as "JUGAAD" in hindi.
On some phones (specially on Samsung ones) some custom fonts are cuted off (or clipped). I had this with custom italic font. Some say that you can edit font to add some kind of padding (i can't confirm that because my lack of knowledge of editing fonts) but:
- EditText/TextView add some padding from xml
- Ellipsize (on some devices messing with this helps displaying text correctly)
Also could you post screenshot with enabled developer options to draw layout bounds, this could help to resolve your problem if above solutions won't help

Is there no prompt in the Android 4.x spinner anymore?

I'm new to Android development and found that I can setup a android:prompt attribute to a Spinner widget. Like so in my layout/my_layout_fragment.xml:
<Spinner
android:id="#+id/boxFunction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_gravity="left"
android:layout_row="14"
android:entries="#array/function_options"
android:gravity="fill_horizontal"
android:prompt="#string/function_prompt" />
I found several screenshots from the Android 2.x epoch which clearly shows the prompt, but I haven't had any luck finding any 4.x screenshots which shows me the prompt. And my compiled app on Android doesn't show it either.
Was the prompt deprecated in 4.x (and if so, where can I get the deprecated information)? Or did I miss something?
I don't think it is deprecated. Maybe from 4.0 it depends on another attribute called
android:spinnerMode
Here is a example which shows you how the prompt works with Spinner Mode attribute.
And before that let me make it clear that,spinnerMode can be set to either dialog or dropdown.
<Spinner android:layout_width="wrap_content"
android:id="#+id/spinner"
android:layout_height="wrap_content"
android:prompt="#string/app_name"
android:spinnerMode="dialog"/>
<Spinner android:layout_width="wrap_content"
android:id="#+id/spinner1"
android:layout_height="wrap_content"
android:prompt="#string/app_name"
android:spinnerMode="dropdown"
android:layout_below="#+id/spinner"
/>
As you can see the first spinner has the spinnerMode set to dialog and the next spinner set to dropdown.
here are the outputs,
Dialog Mode
drop Down
The prompt title I have used here is "Locale Test". Thought I have set it to both the spinners it is visible only in Dialog Mode spinner. So I think it speaks for it.

Categories

Resources