I am trying to create a full width auto complete text field.
So far, I think I have the text field itself looking right. The problem is with the auto complete popup. It has this very bold shadow all around it and I just can't get rid of it.
Don't get me wrong, I still want the shadow, but a subtle shadow, only on the bottom of the popup, not all around it (especially not at the top, that's really weird).
Something like this:
Here's what mine looks like (sorry for giant image):
The Code
activity_main.xml:
<AutoCompleteTextView
android:id="#+id/actvSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="8dp"
android:background="#drawable/full_width_input"
android:completionThreshold="1"
android:hint="Search a movie..."
android:textColorHint="#BDBDBD"
android:elevation="0dp"
android:popupBackground="#android:color/white" />
full_width_input.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-1dp" android:right="-1dp" android:left="-1dp">
<shape android:shape="rectangle">
<padding android:bottom="20dp" android:top="20dp" android:left="16dp" android:right="16dp" />
<solid android:color="#android:color/white" />
<stroke android:width="1dp" android:color="#E0E0E0" />
</shape>
</item>
</selector>
use android:popupElevation="0"
<AutoCompleteTextView
android:id="#+id/actvSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="8dp"
android:background="#drawable/full_width_input"
android:completionThreshold="1"
android:hint="Search a movie..."
android:textColorHint="#BDBDBD"
android:popupElevation="0dp"
android:popupBackground="#android:color/white" />
This question is a bit old already, but anyways. I just crossed through this problem. I was using android:popupBackground="#null" for my autocomplete, but it DOES NOT WORK PROPERLY ON ANDROID 6 (I just tested it).
Instead of using android:popupBackground="#null", use android:popupBackground="#android:color/transparent" (it will also work for the Android 4.4 and 5.0).
If we set android:popupBackground="#null" in AutoCompleteTextView and set background for the adapter row as white, we can achieve this. Hope it will help you.
What I ended up doing is manually creating the auto complete using a ListView.
It took a bit of hacking around but now I have the exact design I had in mind.
Related
I am trying to create a capsule/pill shaped button in XML. I have defined a drawable and set it as the background of my button, but in the preview, and when I run the app, it's displaying as a blue rectangle, despite the background drawable being a white oval. Does anyone know why that might be happening?
Here's the button:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/search_box"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:background="#drawable/button_capsule"
android:text="#string/search"
android:textColor="#color/precipLightBlue"/>
And here's the background drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="1000dp" />
<solid android:color="#android:color/white" />
</shape>
To have a capsule/pill shaped button you can use the MaterialButton in the official Material Component library using the app:cornerRadius attribute.
<com.google.android.material.button.MaterialButton
android:layout_width="100dp"
app:cornerRadius="32dp"
..../>
With the version 1.1.0 you can also customize the shape of your component using the app:shapeAppearanceOverlay attribute
<com.google.android.material.button.MaterialButton
....
app:shapeAppearanceOverlay="#style/ShapeAppearanceOverlay.ButtonRounded"
.../>
In the style define:
<style name="ShapeAppearanceOverlay.ButtonRounded" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">32dp</item>
</style>
You can also try to use the ExtendedFloatingActionButton:
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/exfab"
android:layout_width="wrap_content"
.... />
You put a shape that you didn't defined. To define an oval you should put the shape="oval" option in the tag. Although i think you want a rectangle with rounded corners as i see in your code.
Also 1000dp radius is a lot, maybe that's making an issue.
Define size too. Because that shape doesn't have any size and may not appear as you are using wrap_content in the button definition
Try this:
<corners android:radius="30dp" />
<solid android:color="#android:color/white" />
<size
android:width="200dp"
android:height="50dp"/>
If you want an oval remove the corners tag and add android:shape="oval" as property of shape tag
Here is the code regarding button drawable background.
Xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center|top"
android:background="#color/colorLightPurple">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:background="#drawable/button_bg"
android:text="Search"
android:textColor="#color/colorBlue"/>
</LinearLayout>
For button background , please add same drawable file
seems like you're doing everything right. Just a small addition, try adding android:shape="rectangle" in the shape tag.
This is what button_capsule.xml should look like.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1000dp" />
<solid android:color="#android:color/white" />
</shape>
Hope this works. All the best.
In Material design version 1.2.0 they have fixed this issue and added a property for setting background for Material Button
here is the dependency for the latest version
com.google.android.material:material:1.2.0
and also if u want to remove the space between the drawable top and bottom so that the drawable get the whole width and height use these 2 properties
android:insetTop="0dp"
android:insetBottom="0dp"
if want to explore more about the properties u can refer to the release of library and can check all the properties.
https://github.com/material-components/material-components-android/releases/tag/1.2.0
use this.
<androidx.appcompat.widget.AppCompatButton
.....
/>
I am using a dark background for my app. The text color of edittext is set as white. It is working fine in latest versions. But in older versions since the edittext itself is displaying as white color i am not able to see the entered text in edittext. how can i handle this?
Make new xml file in res/drawable name it rounded_edit_text then paste this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#F9966B" />
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp" />
</shape>
In res/layout copy and past following code (code of EditText) :
<EditText
android:id="#+id/txtdoctor"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/rounded_edit_text"
android:ems="10" >
<requestFocus />
</EditText>
You can use this thing as it included in API level 1:
editText.setTextColor(getResources().getColor(R.id.your_color));
editText.setBackgroundColor(getResources().getColor(R.id.your_color));
You are setting the background as color white in your style.xml. In older version it will also set as background color of editttext,dialog like views; please check this answer. It is about setting android:windowBackground and android:colorBackground . Hope it will help you.
Hi guys i have looked at various sites on how to customize the spinner but they have been poor and have not helped me to achieve the look i want. So i have tried to use the rules of customizing a button to help. Here is my code
spinner
<Spinner
android:id="#+id/spinner1"
android:layout_height="30dp"
android:layout_width="300dp"
android:layout_marginLeft="70dp"
android:layout_marginRight="0dp"
android:layout_marginTop="210dp"
android:background="#drawable/scannershape"
android:spinnerMode="dropdown"
/>
background of spinner
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#fafafa"
android:centerColor="#ffffff"
android:endColor="#fafafa"
android:angle="360"/>
<padding android:left="6dp"
android:top="6dp"
android:right="6dp"
android:bottom="6dp" />
<corners android:radius="0dp" />
<stroke android:width="2px" android:color="#cfcfcf" />
</shape>
The look is almost perfect but there are a few things missing.
1,First of all with the normal spinner when it is clicked there is a brief moment when the scanner turns bright orange to show you have clicked it. How do i do this in my customization as it no longer does this anymore in my customized version? and if possible but not important change this color to orange.
2, Secondly the normal spinner has a arrow that points downward to indicate a dropdown list. This is also lost in my customization. How do i customize this arrow into my spinner?
finally were is this file located so i can see if the answers to my question might be there?
android:background="#android:drawable/btn_dropdown"
You may use selector. There's a question for buttons, it's the same for spinner, I think
I am trying to set the background color of a button in my app and I am unable to achieve the result that I want...
The color that I am trying to set is holo_green_light(#ff99cc00). In order to do it, I am using setColorFilter(0xff99cc00, PorterDuff.Mode.MULTIPLY);
The color that I get is not the holo_green_light but a mix of lightgrey and holo_green_light.
I have tried using the LightingColorFilter without much success.
Is there a way to do it programatically, so that the button appears like a button and not a flat rectangle with the color that I need.
If you want to keep the general styling (rounded corners etc.) and just change the background color then I use the backgroundTint property
android:backgroundTint="#android:color/holo_green_light"
This is my way to do custom Button with a different color:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="3dp"
android:color="#80FFFFFF" />
<corners android:radius="25dp" />
<gradient android:angle="270"
android:centerColor="#90150517"
android:endColor="#90150517"
android:startColor="#90150517" />
</shape>
This way you set as background:
<Button android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_marginBottom="25dp"
android:layout_centerInParent="true"
android:background="#drawable/button" />
If you don't mind hardcoding it you can do this ~> android:background="#eeeeee" and drop any hex color # you wish.
Looks like this....
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:text="#string/ClickMe"
android:background="#fff"/>
Create /res/drawable/button.xml with the following content :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<!-- you can use any color you want I used here gray color-->
<solid android:color="#90EE90"/>
<corners
android:bottomRightRadius="3dp"
android:bottomLeftRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp"/>
</shape>
And then you can use the following :
<Button
android:id="#+id/button_save_prefs"
android:text="#string/save"
android:background="#drawable/button"/>
Just use a MaterialButton and the app:backgroundTint attribute:
<MaterialButton
app:backgroundTint="#color/my_color_selector"
Why not just use setBackgroundColor(getResources().getColor(R.color.holo_light_green))?
Edit: If you want to have something which looks more like an Android button you are going to want to create a gradient and set it as the background. For an example of this, you can check out this question.
No need to be that hardcore.
Try this :
YourButtonObject.setBackground(0xff99cc00);
Try this
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="34dp"
android:text="Check Out"
android:textAllCaps="true"
android:background="#54c2bc"
android:textColor="#FFFFFF"
android:textSize="9sp"/>
In order to keep the style, use:
int color = Color.parseColor("#99cc00");
button.getBackground().mutate().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC));
In addition to Mark Proctor's answer:
If you want to keep the default styling, but have a conditional coloring on the button, just set the backgroundTint property like so:
android:backgroundTint="#drawable/styles_mybutton"
Create the associated file /res/drawable/styles_mybutton.xml, then use the following template and change the colors as per your tastes:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Disabled state-->
<item android:state_enabled="false"
android:color="#android:color/white">
</item>
<!-- Default state-->
<item
android:color="#cfc">
</item>
</selector>
try this
app:backgroundTint="#color/colorGreen"
With version 1.2.0-alpha06 of material design library, now we can use android:background="..." on MaterialButton components:
<com.google.android.material.button.MaterialButton
android:background="#fff"
...
/>
I am trying to design an EditText Field having Shadows (bottom and right side) like this
tried googling & hunted many SO discussions but all are for TextView not EditText.
This is my code adding shadow to Input Text but not to TextField
<EditText android:id="#+id/txtpin"
android:maxLength="4"
android:layout_marginLeft="10dp"
android:layout_height="37dp"
android:gravity="center_horizontal"
android:inputType="textPassword"
android:longClickable="false"
android:layout_width="160dp"
android:shadowColor="#color/Black"
android:shadowDx="1.2"
android:shadowDy="1.2"
android:shadowRadius="1.5"
android:background="#color/White">
<requestFocus></requestFocus>
</EditText>
I guess it needs some custom xml view in drawable but not getting exact idea.
What will be the logic to achieve this.
Any help would be appreciated.
Well.. #Shalini's answer helped me in this way but still I got another way to achieve 2D shadow with EditText Field and I am going to share with you.
We need to create custom XML view with three layer for EditText,
bottom shadow and right side shadow
Below is my code.
res/drawable/edittext_shadow.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- most important is order of layers -->
<!-- Bottom right side 2dp Shadow -->
<item >
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<!-- Bottom 2dp Shadow -->
<item>
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<!-- White Top color -->
<item android:bottom="3px" android:right="3px">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
Now we can set this shadow view to our TextField using "Background" property
like this
res/layout/main.xml
<EditText android:layout_width="wrap_content"
android:id="#+id/txtpin"
android:maxLength="4"
android:layout_height="37dp"
android:gravity="center_horizontal"
android:longClickable="false"
android:padding="2dp"
android:inputType="textPassword|number"
android:password="true"
android:background="#drawable/edittext_shadow"
android:layout_weight="0.98"
android:layout_marginLeft="15dp">
<requestFocus></requestFocus>
</EditText>
and the result screen is like I have posted in question above.
Thanks to SO, sharing knowledge.
This works for me..
<EditText
android:layout_width="fill_parent"
android:shadowRadius="2"
android:shadowColor="#0000ff"
android:shadowDx="2"
android:shadowDy="4"
android:id="#+id/EditText01"
android:layout_height="wrap_content" />
Hope it helps:)
From Shadow Effect for a Text in Android?, perhaps you'd consider using
android:shadowColor,
android:shadowDx,
android:shadowDy,
android:shadowRadius;
Alternatively:
setShadowLayer()