Giter VIP home page Giter VIP logo

Comments (5)

zumpar avatar zumpar commented on July 24, 2024

Hi,

could you post some example code that uses submenus? I'm unable to create them programmatically or through a xml menu resource.

edit: I forgot to mention I'm trying to create them on a phone. Is this possible?

Thanks!
Paul

from actionbarsherlock.

JakeWharton avatar JakeWharton commented on July 24, 2024

The 'styled' sample contains two submenus which are created from a menu XML. Here is a snippet of one of them:

<item android:id="@+id/menu_nav" android:title="@string/action_label_nav">
    <menu>
        <group android:id="@+id/menu_nav_group" android:checkableBehavior="single">
            <item android:id="@+id/menu_nav_tabs" android:title="@string/action_label_nav_tabs" android:checked="true" />
            <item android:id="@+id/menu_nav_drop_down" android:title="@string/action_label_nav_drop_down" />
            <item android:id="@+id/menu_nav_label" android:title="@string/action_label_nav_label" />
        </group>
    </menu>
</item>

The <group> tag is only utilized here because the sub-menu items are all checkable.

Creating the above menu prorgammatically would start something like this:

public void onCreateOptionsMenu(Menu menu) {
    SubMenu subMenu = menu.addSubMenu(0, R.id.menu_nav, 0, R.string.action_label_nav);
    subMenu.addItem(0, R.id.menu_nav_tabs, 0, R.string.action_label_nav_tabs);
    subMenu.addItem(0, R.id.menu_nav_drop_down, 0, R.string.action_label_nav_drop_down);
    subMenu.addItem(0, R.id.menu_nav_label, 0, R.string.action_label_nav_label);
}

In this example I use R attributes for the ids and titles but you may use literal numbers and strings as well.

from actionbarsherlock.

zumpar avatar zumpar commented on July 24, 2024

Thank you!

On a tablet, this works great, but I'm unable to get it working on pre-3.0 devices, so I'm guessing it's just for tablets.

from actionbarsherlock.

segundoacosta avatar segundoacosta commented on July 24, 2024

Hola, como puedo hacer que al hacer touch en un item se despliegue una lista ??

from actionbarsherlock.

segundoacosta avatar segundoacosta commented on July 24, 2024

Como se puede hacer el siguiente menú por código sin usar un layout.xml.
Translate:
Can this be done straight through Java or must I use layout.xml?

<item
android:icon="@drawable/menu"
android:showAsAction="ifRoom">
<menu android:id="@+id/menuopciones">

    <item
        android:id="@+id/vivo"
        android:title="VIVO"
        android:showAsAction="ifRoom|withText"    
        android:icon="@drawable/vivoon"
    />

    <item
        android:title="VOD"
        android:id="@+id/vod"
        android:showAsAction="ifRoom|withText"    
        android:icon="@drawable/vodon"
    />

    <item
        android:title="RPVR"
        android:id="@+id/npvr"
        android:showAsAction="ifRoom|withText"        
        android:icon="@drawable/npvron"        
    />

</menu>

from actionbarsherlock.

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.