Android Question Round Selected Corners of view's (Rounding Custom Corner)

Poya.B4A

Member
Hi there;
I'm trying to round Custom Corner of some view's but just change the buttom background view, TNX for any replay.

B4X:
Sub Button1_Click
    Dim sizee As Int = SeekBar1.Value
    Panel1.Invalidate  'I put this code befor and after the next line but no change
    Custom_RoundCorners(Panel1,sizee,sizee,0,0)
    Panel1.Invalidate
   
    Custom_RoundCorners(Button1,sizee,sizee,0,0)
   
    Custom_RoundCorners(ImageView1,sizee,sizee,0,0)
    ImageView1.Invalidate
   
End Sub

JavaCode Sub 👇

B4X:
Sub Custom_RoundCorners(View As View, topLeftRadius As Float, topRightRadius As Float,bottomRightRadius As Float, bottomLeftRadius As Float)
#If java
import android.graphics.Outline;
import android.graphics.Path;
import android.view.View;
import android.view.ViewOutlineProvider;

public void roundCustomCorners(View view, float topLeftRadius, float topRightRadius, float bottomRightRadius, float bottomLeftRadius) {
    view.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            Path path = new Path();
            path.addRoundRect(0, 0, view.getWidth(), view.getHeight(), new float[] {topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius}, Path.Direction.CW);
            outline.setConvexPath(path);
        }
    });
    view.setClipToOutline(true);
}
#End If
    Dim jo As JavaObject
        jo.InitializeContext
        jo.RunMethod("roundCustomCorners",Array(View,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius))
       
        Log("Success...")
End Sub
 

Attachments

  • Custom Corner Round.rar
    434 KB · Views: 20
Last edited:

asales

Expert
Licensed User
Longtime User
I don't understand what you want to do with this code.

Try to change the Drawable property of the button to Statelistdrawble or declare the button as B4XView and use the property SetColorAndBorder.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Last edited:
Upvote 1
Solution

Poya.B4A

Member
Check this to round only come corners
yeah, excellent , that's fine

👇

B4X:
'    Specifies radii for each of the 4 corners:
'   For each corner, the array contains 2 values, [X_radius, Y_radius].
    Dim jo As JavaObject = Panel1.Background
        jo.RunMethod("setCornerRadii", Array(Array As Float(120, 120,  0, 0,  120, 120,  0, 0)))  '3 corners rounded
 
Upvote 0
Top