PopupWindow showing a border - android

When creating a PopupWindow it shows a border like in the following image:
How do I remove it?

Try to add this line :
mPopup.setBackgroundDrawable(new BitmapDrawable());

You can create one custom style and put that border the same color on background, try something like:
New | Android XML File.
myborder.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dip"
android:color="#android:color/darker_gray" />
<solid
android:color="#android:color/background_dark" />
<padding
android:left="7dip"
android:top="7dip"
android:right="7dip"
android:bottom="7dip" />
<corners
android:radius="6dip" />
</shape>
Using the drawable Android XML file in a layout
Layout.xml
<LinearLayout
android:orientation="vertical"
android:background="#drawable/myborder"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Text"
/>
<!-- ..................... -->

You need to create a custom layout and set border of parent layout,
i'll giving you a Logical idea for doing this.
Your layout must be like below.
dialog_layout.xml
<RelativeLayout>
<LinerLayout> <!-- You can **Set/Remove** all background properties of this LinearLayout-->
<!-- Here are all child element like EditText/ Or TedxView-->
</LinerLayout>
</RelativeLayout>
Here are link for border :
Border

Related

How to merge an edittext with spinner in Android?

How can I make an EditText with a drop-down in Android?
For reference i have added an image. I am trying to combine an edittext with spinner but I am not able to achieve the same.
Can anyone add suggestion or xml mockup?
Well, You can use a LinearLayout with a horizontal orientation and create a custom drawable for the rounded border.
Implementation
First, you need to draw the rounded border by creating a new Drawable resource file.
In your res/drawables folder create rounded_border.xml
rounded_border.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<stroke android:width="2dp" android:color="#2E2E2E" />
</shape>
</item>
</selector>
Then, you can add the LinearLayout to your layout as follows.
your_layout.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#drawable/rounded_border"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#null"
android:paddingHorizontal="16dp"
android:text="(504) 596-3245"
android:layout_weight="2"/>
<View
android:layout_width="2dp"
android:background="#2E2E2E"
android:layout_height="match_parent"/>
<Spinner
android:layout_width="0dp"
android:layout_height="match_parent"
tools:listitem="#layout/spinner_item_text"
android:layout_weight="1"/>
</LinearLayout>
Remarks
You can Customize the border width, color, and radius from the rounded_border.xml.
Final Results
could refer this lib demo : https://github.com/z2wenfa/SpinnerEditText
could use the lib directly
dependencies {
compile 'com.github.z2wenfa:SpinnerEditText:1.0.1'
}
or could refer: https://github.com/z2wenfa/SpinnerEditText/blob/master/spinneredittext-lib/src/main/java/com/z2wenfa/spinneredittext/SpinnerEditText.java

Add a circular progress icon inside the chip view

I want to add a circular progress icon like
Inside a chip view in android. Some thing like this as the end product
Excuse the background of the progress bar indicator. I am not able to find any thing regarding this. Any suggestion?
You can achieve this behaviour by setting programmatically the ChipIcon using an androidx.swiperefreshlayout.widget.CircularProgressDrawable if you want to align the loading indicator in the left side of your Chip or you can use the CloseIcon if you want to align it on the right side of the Chip.
Align CircularProgressDrawable on the left side of chip:
1.In your chip xml layout define the chipIconSize and padding attributes based on your needs like below:
<com.google.android.material.chip.Chip
android:id="#+id/chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chip"
app:chipIconSize="25dp"
app:iconStartPadding="5dp"
app:iconEndPadding="5dp"
app:chipBackgroundColor="#android:color/holo_blue_bright" />
2.Create programmatically your CircularProgressDrawable like below:
CircularProgressDrawable cpDrawable = new CircularProgressDrawable(this);
cpDrawable.setStyle(CircularProgressDrawable.DEFAULT);
cpDrawable.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
cpDrawable.start();
3.And set the above CircularProgressDrawable to your ChipIcon like below:
chip = findViewById(R.id.chip);
chip.setChipIcon(cpDrawable);
chip.setChipIconVisible(true);
Align CircularProgressDrawable on the right side of chip:
1.In your chip xml layout define the closeIconSize and closeIcon paddings attributes based on your needs like below:
<com.google.android.material.chip.Chip
android:id="#+id/chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chip"
app:closeIconSize="25dp"
app:closeIconStartPadding="5dp"
app:closeIconEndPadding="5dp"
app:chipBackgroundColor="#android:color/holo_blue_bright" />
2.Create programmatically your CircularProgressDrawable like above and set it on Chip CloseIcon like below:
chip = findViewById(R.id.chip);
chip.setCloseIcon(cpDrawable);
chip.setCloseIconVisible(true);
Results will be like below:
I created a layout using relative layout, you can check this i hope you get this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:background="#drawable/dummy_bg"
android:splitMotionEvents="true">
<TextView
android:id="#+id/tvlabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="Electronics"
android:textColor="#color/black"
android:textSize="25sp" />
<ProgressBar
android:id="#+id/progrressciruclar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_toRightOf="#+id/tvlabel" />
</RelativeLayout>
also create this dummy_bg in your drawables folder and paste the following code
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dp"
android:color="#FFFFFF" />
<corners android:radius="50dp"/>
<padding android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>

Background drawable not applying to button

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
.....
/>

Creating a circle in xml file is not actually a circle

I have a gradient view which animates from left to right. I have a XML that describes the circle inside, but the borders of XML are actually rectangular as you can see, how can I make the overflow hidden of the outside of the XML.
It looks like that only the background is a circle but not the the shape itself ,I thought that the solution is by using PorterDuff.Mode but it doesn't help.
this is my circle.xml file:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="2dp"
android:color="#android:color/white" />
<corners android:radius="7.5dp" />
<size android:width="327dp" android:height="211.5dp" />
</shape>
And in my layout i use it like this :
<RelativeLayout
android:id="#+id/white_rectangle"
android:layout_width="327dp"
android:layout_height="211.5dp"
android:layout_gravity="center"
android:clipChildren="true"
android:adjustViewBounds="true"
android:background="#drawable/circle"
>
<View
android:id="#+id/scanner"
android:layout_width="123.5dp"
android:layout_height="211.5dp"
android:layout_gravity="center"
android:background="#drawable/scanner"
android:visibility="gone" />
</RelativeLayout>
i don't want the scanner to go outside the borders
You need to set square dimensions for it to appear as a circle.
Your width is larger than your height. Try this
<RelativeLayout
android:id="#+id/white_rectangle"
android:layout_width="211.5dp"
android:layout_height="211.5dp"
android:layout_gravity="center"
android:clipChildren="true"
android:adjustViewBounds="true"
android:background="#drawable/circle"
>
<View
android:id="#+id/scanner"
android:layout_width="123.5dp"
android:layout_height="123.5dp"
android:layout_gravity="center"
android:background="#drawable/scanner"
android:visibility="gone" />
</RelativeLayout>
The solution for me was to use CardView and give it cardCornerRadius.
found it here How to make a view in android with rounded corners
try this library. Use same height and width for view
https://github.com/hdodenhof/CircleImageView

Ripple effect over the actual border

I have created a listview and added a border to it's items.
something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal"
android:background="#drawable/listviewborderbox"
android:padding="10dp" >
<LinearLayout
android:id="#+id/sharedbyyouNameLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".70"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/sharedbyyoutext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="#string/sampletext1"
android:textColor="#color/blackText"
android:textSize="14sp" />
<TextView
android:id="#+id/sharedbyyouselected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="#string/sampletext2"
android:textColor="#color/blackText"
android:textSize="16sp"
tools:ignore="RtlHardcoded" />
</LinearLayout>
<LinearLayout
android:id="#+id/sharedbyyouLayoutforarrow"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".10"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_next"
tools:ignore="RtlSymmetry,RtlHardcoded,ContentDescription" />
</LinearLayout>
</LinearLayout>
And I have ripple effect value in Drawable-v21 like this:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#android:color/white"> <item android:drawable="#color/footercolor"/> </ripple>
Border shape xml in drawable folder is this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/colorforbodybox" />
<corners android:radius="10dip"/>
<stroke android:width="2dip" android:color="#color/colorforborder" />
</shape>
Ripple effect works but ripple effect is shown outside the border line that I have drawn. Please check pic below:
How do I make the ripple effect not to cross the border in the list view?
To achieve rounded corner ripple effect change your ripple xml file to:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#android:color/white"
tools:targetApi="lollipop">
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<corners android:radius="10dp"/>
<solid android:color="#color/footercolor"/>
</shape>
</item>
</ripple>
The problem I had was that the corner radius of my views was not a fixed value therefore using the xml suggested didn't work for me.
I needed a something that would adapt the ripple effect every time regardless of the shape used so...
I used a simple view extension:
fun View.addRippleEffect(rippleColorId: Int = R.color.rippleColor) { // Here you can pass the color you want for the ripple effect and assign a "default" value
val rippleColor = ColorStateList.valueOf(ContextCompat.getColor(App.context(), rippleColorId))
this.background = RippleDrawable(
rippleColor, // This is the color of the effect and needs to be a ColorStateList
this.background, // ( = content ) With this you use your view's background as the content of the ripple effect
this.background) // ( = mask ) With this the ripple will take the shape of the background and not "spill over". (Could be null IF you did set the previous variable "content = this.background")
}
OR, if you want to separate the two layers:
fun View.addRippleEffect(rippleColorId: Int = R.color.rippleColor) {
val rippleColor = ColorStateList.valueOf(ContextCompat.getColor(App.context(), rippleColorId))
this.foreground = RippleDrawable( //Using the foreground allows you to give the view whatever background you need
rippleColor,
null, //Whatever shape you put here will cover everything you've got underneath so you probably want to keep it "null"
this.background)
}
Basically you give a view a background (rounded rectangle with borders in your case) then you can simply call the extension in your Activity/Fragment:
whateverView.addRippleEffect()
//or
whateverView.addRippleEffect(R.color.red)
See: https://developer.android.com/reference/android/graphics/drawable/RippleDrawable
1. Create the Ripple Drawable Contains the Backgound Shape
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?colorControlHighlight"> //defaul ripple color
<item>
<shape //the background shape when it's not being click
android:shape="rectangle">
<solid
android:color="#color/colorPrimary" />
<corners
android:radius="32dp" />
</shape>
</item>
</ripple>
2. Applying the Drawable to the View and REMOVE THE SHADOW
<Button
style="?borderlessButtonStyle" //remove the default shadow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_button" //here
android:text="Sign up"
android:textAllCaps="false"
android:textColor="#android:color/white" />
Try setting clipToOutline of your View / ViewGroup to true, either in the code or through XML, it should limit the ripple's area accordingly (as long as you background shape matches the requirements, see the docs for more details).

Categories

Resources