How to delete white corners - android

how to get rid of there white corners after adding the backround?
Edit: It's a dialog pop up
It looks like this:
And here's the code:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/color_choose_dialog"
//and here's code for the background:
`<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#color/md_theme_light_onPrimary" />
<corners
android:radius="30dp" />
<padding
android:left="20dp"
android:top="20dp"
android:right="20dp"
android:bottom="20dp" />
</shape>
Thanks for any help!!!

AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
....
AlertDialog alertDialog = builder.create();
//remove white space
alertDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
alertDialog.show();

I think you need to use a card instead of using ConstraintLayout and use
app:cardCornerRadius="20dp"
I think this will solve your problem

Try to change background color from white to transparent. Corners' white color will become invisible.

Related

How to make visible the click action on Button?

When we click the Button,the background change color to some black transparent color. But, when I change the background of Button, the user can't see the visual reaction of Button when he click on them.
Thank you for your help.
For v21 and above you can use:
bg_button.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:drawable="#drawable/button_normal" />
</ripple>
In your Button:
<Button
...
android:background="#drawable/bg_button" />
Important: if button has disable state ripple effect not shows.
More: https://guides.codepath.com/android/ripple-animation
Thank you !
This is my answer and i use it well.
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#color/blackTrans"
tools:targetApi="lollipop">
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#color/blackTrans" />
</shape>
</item>
</ripple>
#color/blackTrans is a black color with transparency

Prevent Spinner Underline become bold during click

I need to add an underline below my Spinner. From these links:
Android Spinner Underline color
I want to underline spinner (android)
I have implemented the below:
In reminder_dialog_fragment.xml
<android.support.v7.widget.AppCompatSpinner
android:id="#+id/spinner_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Widget.AppCompat.Spinner.Underlined"
android:theme="#style/MySpinnerTheme" />
In styles.xml
<style name="MySpinnerTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- set color for underline below Spinner -->
<item name="colorControlActivated">#ffcfd8dc</item>
<item name="colorControlHighlight">#ffcfd8dc</item>
<item name="colorControlNormal">#ffcfd8dc</item>
</style>
I managed to display underline below Spinner & change the underline's color. But during spinner onclick / highlighted, there is some animation effect on Spinner:
Ripple effect on the triangle (right side of Spinner)
The underline below Spinner become bold
How can I remain the effect of (1), but disable the effect of (2)?
In other words, I want to prevent the underline become bold when Spinner is clicked.
may be you can try
android:elevation="5dp"
in xml
Try to use below code snippet for removing Spinner Bottomline color
app:ms_basecolor="#android:color/transparent"
app:ms_hightlightcolor="#android:color/transparent"
I hope it will work for you!
There are multiple ways to do it. Try to give background as transparent.
<Spinner
android:id="#+id/spTest"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="#string/spinner_prompt"
android:background="#android:color/transparent"
android:entries="#array/spinnerList"/>
Or create an EditText as shown in the code below:
<EditText
android:id="#+id/etTest"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:layout_margin="10dp"
android:background="#drawable/edittext_rectangale_border"
android:drawableEnd="#drawable/ic_arrow_drop"
android:focusable="false"
android:focusableInTouchMode="false"
android:hint="#string/spinner_prompt"
android:inputType="text"
android:padding="5dp" />
You can find the drop_down_arrow from the vector asset. For the Border of EditText create a drawable named "edittext_rectangle_border.xml" and paste the below code in it.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke
android:width="3dp"
android:color="#B9B9B9"/>
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp"/>
<corners
android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp"/>
</shape>
After completing the above things, Open the java file and create a Dialog on EditText click by using onSetClickListner and display the list in the dialogbox. Later on selection of item set the EditText text.
Hope you find it useful.

Set SeekBar's progress color to transparent

Here is a picture of what I want to accomplish, where there is no progress color (transparent), with a solid grey background bar:
I tried
android:progressTint="#00000000"
But that sets the whole bar (progress bar AND the back bar) to transparent.
I also tried:
android:progressDrawable="#drawable/customseekbar"
where customseekbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#android:id/background"
android:drawable="#drawable/seekbar_background" />
<item android:id="#android:id/progress">
<clip android:drawable="#drawable/seekbar_background" />
</item>
and seekbar_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#FF555555" />
</shape>
but then I get this fat and ugly:
What am I doing wrong here? Thanks
How to Style a Seekbar in Android
Here you go, you need to do the following
Step 1:
In drawable, put "progress_bg.png" (find attached)
Step 2:
In drawable, create "myprogessbar_style.xml", and insert the following
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background"
android:drawable="#drawable/progress_bg" />
<item
android:id="#android:id/secondaryProgress"
>
<scale
android:drawable="#drawable/progress_bg"
android:scaleWidth="100%"/>
</item>
<item
android:id="#android:id/progress"
android:drawable="#drawable/progress_bg"/>
</layer-list>
Step 3:
Your seekbar
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:indeterminate="false"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:progressDrawable="#drawable/myprogessbar_style"/>
Result
Attachment
P.S. Yes, it's not a transparency but the expected result
This seems to work:
<SeekBar
...
android:progressTint="#android:color/transparent"
... />
seekbar_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:height="1px" android:color="#FF555555" />
</shape>
1px line shape
android:maxHeight="3dp" add this to your layout xml where you have mentioned the seekbar. You can change the dp if you wish to decrease the height
That's much easier to solve. In your seekbar_background.xml:
Instead of:
android:color="FF555555"
Try:
android:color="#android:color/transparent"
If you want to do it programatically:
seekBar.progressTintList = ColorStateList.valueOf(Color.TRANSPARENT)
android:background="#android:color/transparent"
This set my SeekBar in Android Studio background to transparent. Pretty straight forward.

How can i set Dialog buttons White image?

This is my Dialog code
AlertDialog.Builder builderofme = new AlertDialog.Builder(this);
final FrameLayout frameView = new FrameLayout(this);
builderofme.setView(frameView);
builderofme.setCancelable(true);
builderofme.setPositiveButton(" Yes ", new OkOnClickListener());
builderofme.setNegativeButton(" No ", new CancelOnClickListener());
final AlertDialog alertDialog = builderofme.create();
LayoutInflater inflater = alertDialog.getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.myediteddialog, frameView);
alertDialog.show();
The Code is working Perfectly.But i want to use the White background for Yes and No button.Presently its coming like this..
This is my myediteddialog.xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical"
android:background="#drawable/delete"
>
<TextView
android:id="#+id/editeddialogboxtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/background_dark"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Do You Want To Delete?"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
Currently you are using the default theme that's because you are not getting the background color as Dark holo theme I would suggest if you want a consistent theme on all the devices then you should declare buttons in the xml file itself and then use it accordingly. This would be the best and right approach in my experience.
you can see the next example.
Creating a Custom Layout
If you want a custom layout in a dialog, create a layout and add it to an AlertDialog by calling setView() on your AlertDialog.Builder object.
By default, the custom layout fills the dialog window, but you can still use AlertDialog.Builder methods to add buttons and a title.
Here You can declare the two buttons in the layout files of myediteddialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical"
android:background="#drawable/delete"
>
<TextView
android:id="#+id/editeddialogboxtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/background_dark"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Do You Want To Delete?"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/stopButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="ffffff"
android:text="Yes" />
<Button
android:id="#+id/playButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="ffffff"
android:text="No" />
</RelativeLayout>
I have done this in my way using few xml and not changing anything else.Thought to share with you guys who are going for the solution.
First i have created a custom selector drawable xml file for my button
here it is
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#83776b" />
<gradient android:angle="-90" android:startColor="#5f4427" android:endColor="#cbb59d" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#83776b" />
<solid android:color="#92806c"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#83776b" />
<gradient android:angle="-90" android:startColor="#cbb59d" android:endColor="#92806c" />
</shape>
</item>
</selector>
Then in my activity i have included this two lines
Button b = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
if(b != null)
b.setBackgroundDrawable(getResources().getDrawable(R.drawable.dialogbutton));
Button c = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if(c != null)
b.setBackgroundDrawable(getResources().getDrawable(R.drawable.dialogbutton));
Easy solution for me that has worked.
Use custom dialog , here is the best example
custom dialog
As per your requirement u have to design custom dialog layout this layout contains one textview and 2 buttons which look as default alert dialog. and write listeners for two buttons and design buttons according to your requirement .

How to make a round button?

I'm trying to make a round button, but I don't know how can I do it. I can make button with rounded corners, but how can I can round circle. It's not the same. Please, tell me, is it possible on Android? Thank you.
Create an xml file named roundedbutton.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#eeffffff" />
<corners android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topRightRadius="8dp"
android:topLeftRadius="8dp"/>
</shape>
Finally set that as background to your Button as android:background = "#drawable/roundedbutton"
If you want to make it completely rounded, alter the radius and settle for something that is ok for you.
If using Android Studio you can just use:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#FFFFFF"/>
</shape>
this works fine for me, hope this helps someone.
Create a drawable/button_states.xml file containing:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="rectangle">
<corners android:radius="1000dp" />
<solid android:color="#41ba7a" />
<stroke
android:width="2dip"
android:color="#03ae3c" />
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:radius="1000dp" />
<solid android:color="#3AA76D" />
<stroke
android:width="2dip"
android:color="#03ae3c" />
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>
</item>
</selector>
Use it in button tag in any layout file
<Button
android:layout_width="220dp"
android:layout_height="220dp"
android:background="#drawable/button_states"
android:text="#string/btn_scan_qr"
android:id="#+id/btn_scan_qr"
android:textSize="15dp"
/>
Markushi's android circlebutton:
(This library is deprecated and no new development is taking place. Consider using a FAB instead.)
If you want a FAB looking circular button and you are using the official Material Component library you can easily do it like this:
<com.google.android.material.button.MaterialButton
style="#style/Widget.MaterialComponents.ExtendedFloatingActionButton"
app:cornerRadius="28dp"
android:layout_width="56dp"
android:layout_height="56dp"
android:text="1" />
Result:
If you change the size of the button, just be careful to use half of the button size as app:cornerRadius.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#ffffff"
/>
</shape>
Set that on your XML drawable resources, and simple use and image button with an round image, using your drawable as background.
<corners android:bottomRightRadius="180dip"
android:bottomLeftRadius="180dip"
android:topRightRadius="180dip"
android:topLeftRadius="180dip"/>
<solid android:color="#6E6E6E"/> <!-- this one is ths color of the Rounded Button -->
and add this to the button code
android:layout_width="50dp"
android:layout_height="50dp"
Used the shape as oval. This makes the button oval
<item>
<shape android:shape="oval" >
<stroke
android:height="1.0dip"
android:width="1.0dip"
android:color="#ffee82ee" />
<solid android:color="#ffee82ee" />
<corners
android:bottomLeftRadius="12.0dip"
android:bottomRightRadius="12.0dip"
android:radius="12.0dip"
android:topLeftRadius="12.0dip"
android:topRightRadius="12.0dip" />
</shape>
</item>
You can use a MaterialButton:
<com.google.android.material.button.MaterialButton
android:layout_width="48dp"
android:layout_height="48dp"
android:insetTop="0dp"
android:insetBottom="0dp"
android:text="A"
app:shapeAppearanceOverlay="#style/ShapeAppearanceOverlay.App.Rounded"
/>
and apply a circular ShapeAppearanceOverlay with:
<style name="ShapeAppearanceOverlay.App.rounded" parent="">
<item name="cornerSize">50%</item>
</style>
Round button in Android
You can make a ImageButton with circular background image.
use ImageButton instead of Button....
and make Round image with transparent background
For a round button create a shape:
<?xml version="1.0" encoding="utf-8"?>
<stroke
android:width="8dp"
android:color="#FFFFFF" />
<solid android:color="#ffee82ee" />
<corners
android:bottomLeftRadius="45dp"
android:bottomRightRadius="45dp"
android:topLeftRadius="45dp"
android:topRightRadius="45dp" />
use it as a background of your button link
Update 2021:
Just use the MaterialButton
<com.google.android.material.button.MaterialButton
app:cornerRadius="30dp"
android:layout_width="60dp"
android:layout_height="60dp"
android:text="test" />
width equal height
cornerRadius is half of the width or height
Yes it's possible, look for 9-patch on google. Good articles :
http://radleymarx.com/blog/simple-guide-to-9-patch/
http://ogrelab.ikratko.com/custom-color-buttons-for-android/
You can use google's FloatingActionButton
XMl:
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_dialog_email" />
Java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FloatingActionButton bold = (FloatingActionButton) findViewById(R.id.fab);
bold.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Do Stuff
}
});
}
Gradle:
compile 'com.android.support:design:23.4.0'
I simply use a FloatingActionButton with elevation = 0dp to remove the shadow:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_send"
app:elevation="0dp" />
I like this solution
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="18dp"
app:cardElevation="0dp"
>
<ImageButton
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#null"
android:scaleType="centerCrop"
android:src="#drawable/social_facebook"
/>
</androidx.cardview.widget.CardView>
It is
android.R.drawable.expander_ic_minimized
look into built in android drawables:
http://androiddrawableexplorer.appspot.com/
Use the Image Buttons and make the background as the image you want.
Create the images from the android asset studio link -
" https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html#foreground.type=image&foreground.space.trim=0&foreground.space.pad=0.25&foreColor=rgba(94%2C%20126%2C%20142%2C%200)&backColor=rgb(96%2C%20125%2C%20139)&crop=1&backgroundShape=circle&effects=none&name=ic_home "
and download it, extraxt it , inside that look for mipmap-hdpi folder.
copy the image from the mipmap-hdpi folder and paste it in the drwable folder of your android project.
Now set the background as that image.
I went through all the answers. But none of them is beginner friendly. So here I have given a very detailed answers fully explained with pictures.
Open Android Studio. Go to Project Window and scroll to drawable folder under res folder
Right click, select New --> drawable resource folder
In the window that appears, name the file rounded_corners and click on OK
A new file rounded_corners.xml gets created
Open the file. You are presented with the following code -->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://android.com/apk/res/android">
</selector>
Replace it with the following code -->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="8dp" />
<solid android:color="#66b3ff" />
</shape>
Here the design view can be seen on the right side
Adjust the value in android:radius to make the button more or less rounded.
Then go to activity_main.xml
Put the following code -->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:padding="10dp">
<Button
android:id="#+id/_1"
android:text="1"
android:textSize="25dp"
android:textColor="#ffffff"
android:background="#drawable/rounded_corners"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
</RelativeLayout>
Here I have placed the Button inside a RelativeLayout. You can use any Layout you want.
For reference purpose MainActivity.java code is as follows -->
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I have a Pixel 4 API 30 avd installed.
After running the code in the avd the display is as follows -->
Fully rounded circle shape.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF" />
<stroke
android:width="1dp"
android:color="#F0F0F0" />
<corners
android:radius="90dp"/>
</shape>
Happy Coding!
In case someone needs a floating action button, but doesn't want to depend on the entire material library, here's a minimal implementation that looks exactly the same, has ripple animation, the shadow, and show()/hide() methods with animation.
Widget code:
class CircularImageButton #JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
) : AppCompatImageButton(context, attrs) {
init {
background = null
outlineProvider = pillOutlineProvider
clipToOutline = true
}
fun show() {
if (visibility != VISIBLE) {
visibility = VISIBLE
startAnimation(showAnimation)
}
}
fun hide() {
if (visibility != INVISIBLE) {
visibility = INVISIBLE
startAnimation(hideAnimation)
}
}
override fun setBackgroundColor(color: Int) {
if (backgroundPaint.color != color) {
backgroundPaint.color = color
invalidate()
}
}
private val backgroundPaint = Paint().apply { style = Paint.Style.FILL }
override fun onDraw(canvas: Canvas?) {
canvas?.drawPaint(backgroundPaint)
super.onDraw(canvas)
}
}
val pillOutlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setRoundRect(0, 0, view.width, view.height, view.height.f / 2)
}
}
private val animationDuration = applicationContext
.resources.getInteger(android.R.integer.config_shortAnimTime).toLong()
val showAnimation = ScaleAnimation(
0f, 1f, 0f, 1f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f)
.apply { duration = animationDuration }
val hideAnimation = ScaleAnimation(
1f, .5f, 1f, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f)
.apply { duration = animationDuration }
And the xml, where 40dp is the “mini” version of the FAB.
<CircularImageButton
android:id="#+id/fab"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_your_drawable"
android:scaleType="center"
android:layout_margin="12dp"
android:elevation="3dp"
android:outlineAmbientShadowColor="#7000"
android:outlineSpotShadowColor="#7000"
android:foreground="?attr/selectableItemBackgroundBorderless" />
With jetpack compose, you can customize your button without requiring any 3-party lib or boilerplate code.
Button(
onClick = { /* do something when button clicked*/ },
modifier = Modifier
.width(64.dp)
.height(64.dp),
shape = CircleShape
) {
Icon(Icons.Default.Star, "")
}

Categories

Resources