Comments (8)
@HeaTTheatR Thanks it worked <3. I will post the code below if someone needs it. BTW it will be cool if we could use our own custom icons instead of the predefined ones. Maybe through another variable or something.
Something like:
custom_icon = True
# set True to use your own icons
Or:
icon_path = "path"
# custom path from where the library should load the png
Here is my final code for who needs it:
floatingbutton.py
from kivy.lang import Builder
from kivy.uix.image import Image
from kivymd.ripplebehavior import CircularRippleBehavior
from kivy.properties import StringProperty
from kivymd.button import CircularElevationBehavior, BaseRaisedButton, BaseButton
Builder.load_string("""
<CustomBaseRoundButton>:
canvas:
Clear
Color:
rgba: root.theme_cls.accent_color
Ellipse:
size: self.size
pos: self.pos
size_hint: None, None
size: dp(56), dp(56)
x: Window.width - self.width - dp(10)
y: dp(10)
CustomFloatingActionButtonImage:
source: root.icon
""")
class CustomBaseRoundButton(CircularRippleBehavior, BaseButton):
pass
class CustomFloatingActionButtonImage(Image):
pass
class CustomFloatingActionButton(CustomBaseRoundButton, CircularElevationBehavior, BaseRaisedButton):
background_palette = StringProperty('Accent')
icon = StringProperty('')
pass
main.kv:
FloatLayout:
callback: lambda x: None
CustomFloatingActionButton:
icon: "assets/language-placeholder.png"
from kivymd.
@nitanmarcel MDFloatingActionButton does not provide custom icons.
from kivymd.
@HeaTTheatR Anything else that I could use instead of the MDFloatingActionButton?
from kivymd.
Maybe there's something similar but without an icon to which I can attach a image
from kivymd.
from kivy.app import App
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.image import Image
from kivymd.ripplebehavior import CircularRippleBehavior
from kivymd.theming import ThemeManager
Builder.load_string("""
#:import MDFloatingActionButton kivymd.button.MDFloatingActionButton
<ExampleCustomFloatingButton@FloatLayout>:
ItemMenuForFitness:
source: 'data/logo/kivy-icon-256.png'
size_hint: None, None
size: dp(56), dp(56)
pos_hint: {'center_x': .5, 'center_y': .5}
""")
class ItemMenuForFitness(CircularRippleBehavior, ButtonBehavior, Image):
pass
class Example(App):
theme_cls = ThemeManager()
def build(self):
return Factory.ExampleCustomFloatingButton()
Example().run()
from kivymd.
Thanks :)
from kivymd.
@HeaTTheatR I took a look at your code and got what I wanted with one small problem. I can't find a way to correctly position my button:
Here is my own floating button with custom icon option:
from kivy.lang import Builder
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.image import Image
from kivymd.ripplebehavior import CircularRippleBehavior
from kivymd.theming import ThemeManager
from kivy.properties import StringProperty
from kivymd.button import BaseRoundButton, CircularElevationBehavior, BaseRaisedButton, BaseButton
from kivymd.backgroundcolorbehavior import SpecificBackgroundColorBehavior
from kivy.uix.anchorlayout import AnchorLayout
from kivymd.theming import ThemableBehavior
Builder.load_string("""
#:import MDFloatingActionButton kivymd.button.MDFloatingActionButton
#:import MDLabel kivymd.label.MDLabel
<BaseRaisedButton>
<BaseLanguageButton>:
size_hint: (None, None)
anchor_x: 'center'
anchor_y: 'center'
<BaseRoundLanguageButton>:
canvas:
Clear
Color:
rgba: root.theme_cls.accent_color
Ellipse:
size: self.size
pos: self.pos
size: (dp(48), dp(48))
lbl_text: "Hekp"
padding: dp(12)
theme_text_color: 'Primary'
LanguageButtonImage:
""")
class BaseLanguageButton(ThemableBehavior, ButtonBehavior, SpecificBackgroundColorBehavior, AnchorLayout):
pass
class BaseRoundLanguageButton(CircularRippleBehavior, BaseButton):
pass
class LanguageButtonImage(Image):
source = "assets/language-python.png"
class LanguageSelectorButton(BaseRoundLanguageButton, CircularElevationBehavior, BaseRaisedButton):
background_palette = StringProperty('Accent')
pass
from kivymd.
ItemMenuForFitness:
source: 'data/logo/kivy-icon-256.png'
size_hint: None, None
size: dp(56), dp(56)
x: Window.width - self.width - dp(10)
y: dp(10)
from kivymd.
Related Issues (20)
- MDFileManager sort_by function
- Python self.theme_cls.backgroundColor set after on_start() HOT 6
- RecycleView + adaptive_size + ready list
- Use a `dp` metric to measure the radius value of `MDNavigationItemIcon` HOT 1
- MDFileManager cancel button goes past the right border of window HOT 3
- MDTabsPrimary switch animation duration hardcoded and impossible to disable
- MDDialog headline should be optional
- MDDialog with custom bg color disappears when using @mainthread HOT 1
- No property provided for changing the tab indicator color
- Error importing kivymd.color_definitions when using kivymd_extensions.akivymd HOT 2
- MDDialog hover state change disregards custom md_bg_color HOT 1
- MDTabsSecondary does not allow custom height
- Disabled MDButton fires on_press events if pos_hint defined HOT 1
- ImportError HOT 2
- MDSegmentedButtonItem on_active event not working HOT 1
- Unexpected behaviour of MDSegmentedButton
- MDSwiper not working HOT 1
- MDTabs example is not working HOT 2
- CommonElevationBehavior example code is not working HOT 2
- MDSlider - screen scale support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kivymd.