As mention in the title im trying to make a custom curved bottom nav bar with round edges and transparent curve like this one
and this is the result i have made so far
but as you can see when the selected item is on the most right or left there is a slight reflection to the edge and i’ve tried so many things to fix it but it seems i can’t
here is the CustomNavBarView file
class CurvedBottomNavigationView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
) : BottomNavigationView(context, attrs) {
private val path = Path()
private val paint = Paint()
private var curveCenterX = 0f
private val curveHeightFactor = 1.6f
private val cornerRadius = 120f // Set your desired corner radius
init {
paint.style = Paint.Style.FILL_AND_STROKE
paint.color = context.getColor(R.color.md_theme_onPrimary) // Set your desired color
setBackgroundColor(context.getColor(android.R.color.transparent))
elevation = 1f
}
fun setCurveCenterX(centerX: Float) {
curveCenterX = centerX
invalidate()
}
@SuppressLint("DrawAllocation")
override fun onDraw(canvas: Canvas) {
val width = width.toFloat()
val height = height.toFloat()
val radius = 160f
path.reset()
val controlY = curveHeightFactor * radius // Adjust the factor to change curve height
// Top-left corner
path.moveTo(0f, cornerRadius)
path.arcTo(RectF(0f, 0f, cornerRadius * 2, cornerRadius * 2), 180f, 90f)
// Top-left to curve transition
val curveWidth = 1.3f * radius // Increase the curve width
path.lineTo(curveCenterX - curveWidth / 2, 0f)
path.quadTo(curveCenterX, controlY, curveCenterX + curveWidth / 2, 0f) // Adjust curve width here
// Curve to top-right transition
path.lineTo(width - cornerRadius, 0f)
// Top-right corner
path.arcTo(RectF(width - cornerRadius * 2, 0f, width, cornerRadius * 2), -90f, 90f)
// Right side and bottom
path.lineTo(width, height)
path.lineTo(0f, height)
path.close()
canvas.drawPath(path, paint)
super.onDraw(canvas)
}
}
and here is the xml implementation
<com.grand.ainshihana.core.customTypes.customView.CurvedBottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_16sdp"
android:paddingHorizontal="@dimen/_10ssp"
app:itemActiveIndicatorStyle="@style/Theme.BottomNavigationView.ActiveIndicator"
app:itemIconTint="@drawable/bottom_nav_selector"
app:itemTextAppearanceActive="@style/BottomNavigationViewTextStyle.bold"
app:itemTextAppearanceInactive="@style/BottomNavigationViewTextStyle"
app:itemTextColor="#9DB2CE"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_menu"
tools:visibility="visible" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:elevation="3dp"
android:src="@drawable/ic_home_selected"
app:backgroundTint="@color/md_theme_primary"
app:layout_constraintBottom_toBottomOf="@+id/bottomNavigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.08"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.94"
app:shapeAppearanceOverlay="@style/fab_3_rounded"
app:tint="@color/white"
tools:visibility="visible" />
all i’ve managed to know is that this reflection is happening when the curve iteract with round edge