在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jmartinesp/GoogleNavigationDrawerMenu开源软件地址(OpenSource Url):https://github.com/jmartinesp/GoogleNavigationDrawerMenu开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):GoogleNavigationDrawerMenuThis project aims to let you use a ListView menu similar to the one in the new Google Apps (Keep, Play Music...) without having to do any extra effort. Sorry for the long name, though. IndexFeaturesWith GoogleNavigationDrawerMenu you can:
How to use1. Include the library:Manually (Option A): Download the source code and import Manually (Option B):
Notice the
Automatic (Gradle): Add it to your Application Module's Declare it into your build.gradle
2. Use class in XML or code:Example of how to use it on an XML code:<org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:drawer="http://schemas.android.com/apk/res-auto"
android:id="@+id/navigation_drawer_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
drawer:list_paddingTop="?android:actionBarSize"
drawer:drawer_gravity="start"
drawer:list_mainSectionsEntries="@array/navigation_main_sections"
drawer:list_secondarySectionsEntries="@array/navigation_secondary_sections"
drawer:list_mainSectionsDrawables="@array/drawable_ids"
drawer:list_secondarySectionsDrawables="@array/drawable_ids">
<FrameLayout
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer> You may think 'Ok, so where's the menu?'. Well, the GoogleNavigationDrawer class itself contains it and handles it so you don't have to manually modify it. You can customize it, though, you can find that info in Customizing Section. All the Using GoogleNavigationDrawer in Java Code:ViewGroup container = (ViewGroup) findViewById(R.id.container);
GoogleNavigationDrawer drawer = new GoogleNavigationDrawer(context);
// Here we are providing data to the adapter of the ListView
drawer.setListViewSections(new String[]{"Section A", "Section B"}, // Main sections
new String[]{"Settings"}, // Secondary sections
new int[]{R.drawable.ic_launcher}, // Main sections icon ids
null); // Secondary sections icon ids
// To work correctly, a DrawerLayout must be the only View in a ViewGroup
container.removeAllViews();
container.addView(drawer);
// Now we add the content to the drawer since the menu is already there.
// Also, DrawerLayout forces the contentView to be the first item. Otherwise, you can't click on the menu.
drawer.addView(contentView, 0); GoogleNavigationDrawer extends DrawerLayout. This means you can use DrawerLayout methods and set a DrawerListener to it. 3. Handling selection, opening and closing of the menu:As you cannot access the inner ListView to ensure encapsulation, additional methods have been provided so you can do it by code. This methods are: public boolean isDrawerMenuOpen();
public void openDrawerMenu();
public void closeDrawerMenu(); Also, to handle section selections, a listener has been provided: public void setOnNavigationSectionSelected(OnNavigationSectionSelected listener); You can also easily tell the drawer to change your Activity title based on the selected section via this method: public void setShouldChangeTitle(Activity activity, boolean shouldChangeTitle); 4. Customizing the inner ListView:Finally, customization. The main XML attributes of the class are the following: drawer:list_padding[Top, Bottom, Left, Right]="dimen"
drawer:drawer_gravity="start"
drawer:list_mainSectionsEntries="array"
drawer:list_secondarySectionsEntries="array"
drawer:list_mainSectionsDrawables="array"
drawer:list_secondarySectionsDrawables="array"
drawer:list_headerView="layout"
drawer:list_footerView="layout"
drawer:list_headerClickable="boolean" (default is true)
drawer:list_footerClickable="boolean" (default is true)
drawer:list_secondarySectionsCheckable="boolean" (default is true)
drawer:list_mainSectionsBackground="drawable"
drawer:list_secondarySectionsBackground="drawable"
drawer:list_width="dimension"
drawer:list_background="drawable|color"
drawer:list_[main|secondary]_divider="drawable|color"
drawer:list_[main|secondary]_divider_height="dimension" Example of arrays in <?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="navigation_main_sections">
<item>Home</item>
<item>Some Other</item>
</string-array>
<string-array name="navigation_secondary_sections">
<item>Settings</item>
<item>Info</item>
</string-array>
<array name="drawable_ids">
<item>@drawable/ic_home</item>
<item>@drawable/ic_other</item>
</array>
</resources> Also, both icon drawables and backgrounds should have checked states to keep them consistent with the rest of the library: <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/ic_on"></item>
<item android:drawable="@drawable/ic_off"></item>
</selector> All these attributes can also be set by code. License:This library is licensed under Apachev2:
This means you can use the library in whatever way you want and also I take no responsibility of what it could do (thermo-nuclear explosions and such). Anyway, it would be really nice of you if you could give this library a line in some "About" section in your app. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论