AutoCompleteText not update popup background - java

I am using AppCompatAutoCompleteTextView but I cannot change the background of the dropdown list or neither the color of the background of the selector. I tried color or drawable but nothing change.
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="#+id/topicEt"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="4dp"
android:background="#drawable/corner_shape_spinner_darkness"
android:dropDownHeight="wrap_content"
android:hint="#string/support_select_topic"
android:inputType="none"
android:editable="false"
android:paddingStart="12dp"
android:textAppearance="#style/Body_12"
android:textColor="#color/white"
android:textColorHint="#color/gray200"
android:drawableEnd="#drawable/dropdown_icon_selector"
android:paddingEnd="14dp"
android:dropDownSelector="#color/lightness100"
android:popupBackground="#color/darkness100"/>
Any idea ?

You can change the AppCompatAutoCompleteTextView selector background with app:backgroundTint attribute.
And change the background of the dropdown list programmatically with either:
autoCompleteTV.setDropDownBackgroundDrawable(ColorDrawable(Color.RED))
autoCompleteTV.setDropDownBackgroundResource(resourceId) // takes a color/drawable resource

Related

Button on android app somehow takes a color from title, dunno how to change a title color or button color

button color takes a title color
Troubles with button colors, it always take a title color and idk why, I don't even know how to change a color of title
<Button android:background="#color/white"
android:id="#+id/showGraphButton"
android:foreground="#drawable/changing_show_graph_button_color"
android:foregroundGravity="right"
android:clickable="true"
android:enabled="false"
android:gravity="left"
android:text="Рассчитать корректуру "
android:textColor="#color/darkgrey_spbsut"
android:layout_width="match_parent"
android:layout_height="40dp"
android:backgroundTint="#color/white">
</Button>
</LinearLayout>
</LinearLayout>
Try to delete android:background="#color/white". That thing reset your color of the background to the default value and if you didn't set the value of the color in the resources of the color (in the folder resources -> values-> colors.xml) it will not work

How do you change hint text color in Android Studio?

I cannot get the hint text color to change in my Android application on the log in page.
<AutoCompleteTextView
android:id="#+id/email"
android:textColor="#color/white"
android:backgroundTint="#android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:textColorHint="#android:color/white"
android:inputType="textEmailAddress"
android:maxLines="1" />
I use the textColorHint method as found in many other examples online but I do not know what is wrong with what I am doing.
Use attribute android:textColorHint="YOUR_COLOR" to set hints text color.
In your AutoCompleteTextView, you are using WHITE color for textColor, backgroundTint and textColorHint. Make sure your AutoCompleteTextView background color is different from WHITE.
Here is an working example for AutoCompleteTextView. I have used RED color for textColor, GREEN color backgroundTint and BLUE color for textColorHint.
<AutoCompleteTextView
android:id="#+id/email"
android:textColor="#FF0000"
android:backgroundTint="#00FF00"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Write something..."
android:textColorHint="#0000FF"
android:inputType="textEmailAddress"
android:maxLines="1" />
OUTPUT
Hope this will help you~
Just add the text in the layout's EditText android:textColorHint = "#android:color/ then press ctrl+space and choice your color.

Android adding image to button

I am trying to add an image to a button(image button or normal button) but not in a specific res/drawable folder.
I want this image as a ImageView object or drawable object etc, but I couldn't.
You can set an icon for Button by adding following attribute in XML for Button like this:
android:drawableLeft="#drawable/button_icon"
If you want to know how to do it programmatically, follow this article:
How to programmatically set drawableLeft on Android button?
Or just add 'background':
<Button
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/qrcode"/>
But i think it's better if you use ImageButton, see this example:
<ImageButton
android:id="#+id/searchImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/your_image_drawable" />
Use ImageButton and add src in your background:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/yourImageNameHere"

ImageView backgroud does not change smoothly on button click

I am writing a simple app that changes the application background randomly on button click.
I have a arraylist that contains 5 id's of images that the application should use:
ArrayList<Integer> imageID = new ArrayList<Integer>();
imageID.add(R.drawable.frame_blue);
imageID.add(R.drawable.frame_green);
imageID.add(R.drawable.frame_lilac);
imageID.add(R.drawable.frame_pink);
imageID.add(R.drawable.frame_yellow);
I have two buttons in my layout xml file for next and previous. Both should change Application background when clicked.
I change the image background from this arraylist:
iM.setBackgroundResource(imageID.get(r.nextInt(5)));
and my layout xml looks like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="76dp"
android:onClick="previous"
android:text="Previous" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_alignParentRight="true"
android:onClick="next"
android:text="Next" />
</RelativeLayout>
All works fine on button click's, ImageView background change as I expect, but the problem is the background is not changing smoothly.
It hangs some time. May be the main ui thread will be block for 1 or 2 second and this look like application hangs.
Hangs mean: Some time button remain clicked for a few seconds.
I tried asynctask did not have success. Is there a way to make it change smoothly?
you need to use caching in order to save time and not inflate every time the images
like this : Drawable image_frame_green = getResources().getDrawable(
R.drawable.frame_green);
Have you tried to preload all drawables in cache and then instead of setting the background resource, set the background drawable as background directly.

how can i have a list of icons in my android app;

can any one suggest how can i have a list of icons like browser icon,email icon and contacts icon upon clicking on those it should lead to android browser,email and contacts apps respectively...right now i have done it, upon clicking buttons. Now i want icons(with image and text) instead of buttons...
Check this out:
http://developer.android.com/resources/tutorials/views/hello-formstuff.html#CustomButton
This will show you had to put the images you want in res/drawable/ and then load them up as buttons in your app.
There is no widget icon.
You can do it yourself using a LinearLayout an ImageView and a TextView.
The xml should be something like this:
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/your_image"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/your_icon_text"/>
</LinearLayout>
You can use Android Image Button and set its property "Clickable=true" and do the required work on its click event listener
I thought you want to have ImageButton , clicking on that you want to open particular application/browser/contact list.
ImageButton - Displays a button with an image (instead of text) that can be pressed or clicked by the user
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon/>
If you wants ImageButton with Background button then set android:background attribute, as below:
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
android:background="#drawable/background_image"/>
If you want an image and text in your button, the way I do it is create a 9 patch, so I can define where the text will go using the padding and stretchable areas. Then follow the same instructions as for the Custom Button already mentioned, but use a standard button, not an Image Button.

Categories

Resources