GithubHelp home page GithubHelp logo

FloatingButton with custom icon about kivymd HOT 8 CLOSED

kivymd avatar kivymd commented on June 2, 2024
FloatingButton with custom icon

from kivymd.

Comments (8)

nitanmarcel avatar nitanmarcel commented on June 2, 2024 2

@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.

HeaTTheatR avatar HeaTTheatR commented on June 2, 2024

@nitanmarcel MDFloatingActionButton does not provide custom icons.

from kivymd.

nitanmarcel avatar nitanmarcel commented on June 2, 2024

@HeaTTheatR Anything else that I could use instead of the MDFloatingActionButton?

from kivymd.

nitanmarcel avatar nitanmarcel commented on June 2, 2024

Maybe there's something similar but without an icon to which I can attach a image

from kivymd.

HeaTTheatR avatar HeaTTheatR commented on June 2, 2024
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()

ezgif-5-af1d732a78f7

from kivymd.

nitanmarcel avatar nitanmarcel commented on June 2, 2024

Thanks :)

from kivymd.

nitanmarcel avatar nitanmarcel commented on June 2, 2024

@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

floating-button

from kivymd.

HeaTTheatR avatar HeaTTheatR commented on June 2, 2024

@nitanmarcel

    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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.