Issue in MDIconButton
in android MDIconButton.set_size calculating bg size is too big
i fix it with
def set_size(self, interval): print("here...") self.width = ( "48sp" if not self.user_font_size else self.user_font_size + sp(25) ) self.height = ( "48sp" if not self.user_font_size else self.user_font_size + sp(25) )
@AnEx07 Please edit the example code and attach screenshots that show the icon size before and after your changes...
output in desktop
output in android
__version__ = "0.0.1"
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.button import MDIconButton
from kivy.metrics import sp
KV = '''
MDScreen:
MDIconButton:
icon: "language-python"
pos_hint: {"center_x": .5, "center_y": .75}
md_bg_color: [1,0,0,1]
user_font_size: "30sp"
NewMDIconButton:
icon: "language-python"
pos_hint: {"center_x": .5, "center_y": .35}
md_bg_color: [1,0,0,1]
user_font_size: "30sp"
'''
class NewMDIconButton(MDIconButton):
def set_size(self, interval):
print("here...")
self.width = (
"48sp" if not self.user_font_size else self.user_font_size + sp(25)
)
self.height = (
"48sp" if not self.user_font_size else self.user_font_size + sp(25)
)
class Example(MDApp):
def build(self):
return Builder.load_string(KV)
Example().run()
and also my suggestion is to use sp as a default metrics it behave same almost same in android and desktop
@AnEx07 I don't see any problem ...
the problem is the background size is too big for a given user_font_size in current MDIconButton as shown in upper icon button of output on android screenshot but the background size in lower icon button is seems to be ok while user_font_size is same in both
here real issue i face...
output in desktop
also output in desktop but similar ratio
output in android..
@AnEx07 I don't see this behavior on mobile devices ...
@AnEx07 Please attach the minimal code that reproduces this behavior...
__version__ = "0.0.1"
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.button import MDIconButton
from baseimport import *
from kivy.metrics import sp
KV = '''
MDScreen:
MDIconButton:
id: top1
icon: "delete-sweep"
pos_hint: {"center_x": 0.5,"center_y": 0.75}
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
MDIconButton:
icon: "delete-sweep"
x: top1.x-sp(30)
y: top1.y-sp(30)
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
MDIconButton:
icon: "delete-sweep"
x: top1.x+sp(30)
y: top1.y-sp(30)
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
NewMDIconButton:
id: top2
icon: "delete-sweep"
pos_hint: {"center_x": 0.5,"center_y": 0.35}
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
NewMDIconButton:
icon: "delete-sweep"
x: top2.x-sp(30)
y: top2.y-sp(30)
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
NewMDIconButton:
icon: "delete-sweep"
x: top2.x+sp(30)
y: top2.y-sp(30)
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
'''
class NewMDIconButton(MDIconButton):
def set_size(self, interval):
print("here...")
self.width = (
"48sp" if not self.user_font_size else self.user_font_size + sp(25)
)
self.height = (
"48sp" if not self.user_font_size else self.user_font_size + sp(25)
)
class Example(MDApp):
def build(self):
return Builder.load_string(KV)
Example().run()
please try that one

print("current...")
print(self.user_font_size) # >>> 59.125
print(dp(self.user_font_size)) # >>> 162.59375
print(dp(23)) # >>> 63.25
print(dp(self.user_font_size + 23)) # >>> 225.84375
print("48dp" if not self.user_font_size else dp(self.user_font_size + 23)) # >>> 225.84375
print("new...")
print(self.user_font_size) # >>> 59.125
print(sp(25)) # >>> 59.125
print(self.user_font_size + sp(25)) # >>> 118.25
print("48sp" if not self.user_font_size else self.user_font_size + sp(25)) # >>> 118.25
here is output comparison of current and my script in android... please let me know if i can help with anything else.
I think the problem occurs when you trying to specify the font size in Kivy language and in Class with (def set size) together. Hope this is what you looking for. I have tested the code works fine on my Samsung phone. version = "0.0.1"
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.button import MDIconButton
from kivy.metrics import sp
KV = '''
MDScreen:
MDIconButton:
id: top1
icon: "delete-sweep"
pos_hint: {"center_x": 0.5,"center_y": 0.75}
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
MDIconButton:
icon: "delete-sweep"
x: top1.x-sp(30)
y: top1.y-sp(30)
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
MDIconButton:
icon: "delete-sweep"
x: top1.x+sp(30)
y: top1.y-sp(30)
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
NewMDIconButton:
id: top2
icon: "delete-sweep"
pos_hint: {"center_x": 0.5,"center_y": 0.35}
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
NewMDIconButton:
icon: "delete-sweep"
x: top2.x-sp(30)
y: top2.y-sp(30)
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
NewMDIconButton:
icon: "delete-sweep"
x: top2.x+sp(30)
y: top2.y-sp(30)
right: self.parent.right - sp(50)
user_font_size: "25sp"
mipmap: True
md_bg_color: [0.8,0,0,0.5]
'''
class NewMDIconButton(MDIconButton):
pass
class MDIconButton(MDIconButton):
pass
class Example(MDApp):
def build(self):
return Builder.load_string(KV)
Example().run()