I'm referring to this answer.
It worked, giving me count in front of cart in menu of navigation drawer, but how shall I make the counter TextView inside a circle?
What I want is:
What I get from the above link is that it only displays the text 2, not in a circle.
My code:
menu:--
<item
android:id="@+id/MyCart"
android:icon="@drawable/ic_shopping_cart_black_24dp"
android:title="My Cart"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:actionViewClass="android.widget.TextView"
/>
activity:--
val slideshow =
MenuItemCompat.getActionView(navigationView!!.menu.findItem(R.id.MyCart)) as TextView
//Gravity property aligns the text
slideshow.setGravity(Gravity.CENTER_VERTICAL);
slideshow.setTypeface(null,Typeface.BOLD); slideshow.setTextColor(getResources().getColor(R.color.colorAccent));
//count is added
RetrofitClient.instancecart.listcart(token).enqueue( object :
Callback<CartResponse> {
override fun onFailure(call: Call<CartResponse>, t: Throwable) {
Toast.makeText(applicationContext,"falied", Toast.LENGTH_LONG).show()
}
override fun onResponse(
call: Call<CartResponse>,
response: Response<CartResponse>
) {
val res=response
if (response.isSuccessful) {
val retro: String = response.body()!!.count.toString()
slideshow.setText(retro) //retrofit api count
}
}
})
}