B4A Library AppCompat - Make Material Design apps compatible with older Android versions

Discussion in 'Additional libraries, classes and official updates' started by corwin42, Dec 19, 2014.

  1. Reids

    Reids Member Licensed User

    Finally the actiobar_NavigationItemClick got working,this event is enough to solve this problem :D
    Thank You Very Much!, have a good day there~
     
  2. dragonguy

    dragonguy Active Member Licensed User

    if I have two activity - Main, Second, can I set different color for two activity?

    colorPrimaryDark value only can set in Main activity but how can i set Second activity colorPrimaryDark value?
     
  3. corwin42

    corwin42 Expert Licensed User

    Use two themes and set each theme to one activity:

    Code:
    'For all other activities
    SetApplicationAttribute(android:theme, "@style/Theme.AppCompat")

    'Different themes for special activities
    SetActivityAttribute(Main, android:theme, "@style/MyAppTheme1")
    SetActivityAttribute(Second, android:theme, 
    "@style/MyAppTheme2")

    CreateResource(values, theme.xml,
    <resources>
        <style name=
    "MyAppTheme1" parent="@style/Theme.AppCompat">
            <item name=
    "colorPrimary">#FF9800</item>
            <item name=
    "colorPrimaryDark">#F57C00</item>
            <item name=
    "colorAccent">#FFA726</item>
        </style>
        <style name=
    "MyAppTheme2" parent="@style/Theme.AppCompat">
            <item name=
    "colorPrimary">#009800</item>
            <item name=
    "colorPrimaryDark">#007C00</item>
            <item name=
    "colorAccent">#00A726</item>
        </style>
    </resources>
     
    Last edited: Jul 29, 2016
    MarcoRome, Erel and DonManfred like this.
  4. MarcoRome

    MarcoRome Expert Licensed User

    Hi @corwin42 .
    Great library and thank you very much for this.
    Anyway i see that using version 3.20 works without any problem on Android 5 or >. But crashes if you use Android 4 (which does not happen on the version 2 library that works on both Android version 4/5/6).
    Any suggestion ?
     
  5. chuath

    chuath Member Licensed User

    I had this problem before and solved it with @corwin42's help on post #199
    Follow the steps and it should be resolved.
    particular this step
     
    konradwalsh and MarcoRome like this.
  6. MarcoRome

    MarcoRome Expert Licensed User

    You are right.
    This is the key.
    Now work without problem Android 4 or >.
    Thank you for your help
     
    konradwalsh and chuath like this.
  7. Anser

    Anser Well-Known Member Licensed User

    Hi Corwin,


    With the new version of AppCompat V3.30, will it be possible to show a badge on the ACMenuItem displayed on the ToolBar as shown on the below given post ?

    https://www.b4x.com/android/forum/t...cmenuitem-shown-on-toolbar.68900/#post-446042

    I have seen many apps with this feature, unfortunately, till now, I could not find any other way to get this done on my app. Or am I in the wrong track to get this done ?

    Regards

    Anser
     
    Last edited: Sep 1, 2016
  8. LucianDesign

    LucianDesign Member Licensed User

    Hello! Is there a way to change the corner radius and elevation for ACButton?
     
  9. corwin42

    corwin42 Expert Licensed User

    Yes. It should be possible to put nearly every View as an ActionView to the ActionBar/ToolBar now.

    You can't change the corner radius because it is in the default background drawable of the button.
    You can change the Elevation of every view with the AppCompat.SetElevation() method (on some view types this won't have an effect but ACButton should work).
     
    DonManfred and Anser like this.
  10. Anser

    Anser Well-Known Member Licensed User

    Any sample available demonstrating the usage of the above said.
     
  11. corwin42

    corwin42 Expert Licensed User

    Currently I have none. I needed the feature for the upcoming version of DesignSupport library. But because it works there it should work in the Toolbar, too.
    I will create an example in near future. Maybe I will write some small tutorials for this and other new features.
     
  12. shashkiranr

    shashkiranr Active Member Licensed User

    Hi All,

    I am using ACCheckbox and I want it to be in a custom white color. I am using the below method to set the checked color given in the link https://www.b4x.com/android/forum/threads/checkbox-checked-color.61779/#content
    Code:
    'Pass the Checkbox object and Colors int values to set for each state.
    Sub SetColorTintList(CB As CheckBox,Checked As Int,Enabled As Int,Disabled As Int)

        
    Dim States(3,1As Int

        States(
    0,0) = 16842912   'Checked
        States(1,0) = 16842910    'Enabled
        States(2,0) = -16842910 'Disabled


        
    Dim Color(3As Int = Array As Int(Checked,Enabled,Disabled)

        
    Dim CSL As JavaObject
        CSL.InitializeNewInstance(
    "android.content.res.ColorStateList",Array As Object(States,Color))
        
    Dim CB1 As JavaObject = CB
        CB1.RunMethod(
    "setButtonTintList",Array As Object(CSL))

    End Sub
    It works great on Android 5 and 6 but I am getting the below error in honor4x Android 4.4.4

    Code:
    Exception java.lang.RuntimeException: Method: setButtonTintList not found in: android.support.v7.widget.AppCompatCheckBox
    I checked the google devloper website and the method does not exists but an inherited xml from compactbutton class is present. Any idea what can be done.

    https://developer.android.com/reference/android/support/v7/widget/AppCompatCheckBox.html

    Best,
    SK
     
  13. corwin42

    corwin42 Expert Licensed User

    Instead of
    Code:
    CB1.RunMethod("setButtonTintList",Array As Object(CSL))
    use
    Code:
    CB1.RunMethod("setSupportButtonTintList",Array As Object(CSL))
     
    shashkiranr likes this.
  14. trueboss323

    trueboss323 Active Member Licensed User

    Hi corwin,
    Is there a way to make material dialogs work on Android 4.x ?
     
  15. PABLO2013

    PABLO2013 Active Member Licensed User

    many tks
     
  16. Reids

    Reids Member Licensed User

    Hi corwin, it seem the appacompat lib has a bug in .ButtonColor properties on version 36 google support library, which button displayed as gray button but
    on previous version of 23 google support library button working nicely *this problem occured in android version 4, which not occured on version 6.
    Oh if you suggest me to use .color properties the button will have bigger padding which is not elegant
    your appcompat library ACbutton has .ButtonColor properties which is very cool!
    I forced to use version 36 because design support require support lib of version 36

    Thanks
     
  17. roberto64

    roberto64 Active Member Licensed User

    hello Corwin42, in ACEditText InputType Phone ownership and Numeric, the keypad appears with letters instead of the keyboard with the numbers?
    thank youh
     
  18. aldomoscarda

    aldomoscarda Member Licensed User

    help! please!
    upload_2016-9-26_16-15-44.png
     
  19. DonManfred

    DonManfred Expert Licensed User

    Read the note on appcompat regarding b4a 6+
    Use an uptodate example
     
  20. corwin42

    corwin42 Expert Licensed User

    Remove the #AdditionalRes lines except the ..\resource one.
    As DonManfred said, read the first post for detailed project setup instructions.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice