Java 为“我的导航抽屉”中的每个项目添加数字指示器
我已经停止在Eclipse中编程Android,开始在Android Studio中开发。我在Eclipse中有一个应用程序,其中包含以下导航抽屉: 菜单项有一个数字,指示其中有多少项。我在Eclipse中是通过listview适配器实现的,但在Android Studio中,我有一个menu.xml,其中包含项目信息Java 为“我的导航抽屉”中的每个项目添加数字指示器,java,android,eclipse,android-studio,navigation-drawer,Java,Android,Eclipse,Android Studio,Navigation Drawer,我已经停止在Eclipse中编程Android,开始在Android Studio中开发。我在Eclipse中有一个应用程序,其中包含以下导航抽屉: 菜单项有一个数字,指示其中有多少项。我在Eclipse中是通过listview适配器实现的,但在Android Studio中,我有一个menu.xml,其中包含项目信息 <item android:id="@+id/nav_manage" android:icon="@drawable/ic_menu_m
<item
android:id="@+id/nav_manage"
android:icon="@drawable/ic_menu_manage"
android:title="Resolución OS" />
我如何输入一个数字,如何从Java代码中更新它
感谢并为我的英语感到抱歉,它非常糟糕。定义抽屉布局时,它是这样工作的
<android.support.v4.widget.DrawerLayout
android:id="@+id/root"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- VIEWGROUP FOR MAIN CONTENT -->
<!-- this is what you see by default -->
<!-- VIEWGROUP FOR LEFT DRAWER -->
<!-- set Layout_Gravity as START (or LEFT) -->
<!-- VIEWGROUP FOR RIGHT DRAWER -->
<!-- set Layout_Gravity as END (or RIGHT) -->
</android.support.v4.widget.DrawerLayout>
改为在中。创建计数器布局,即菜单\u counter.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textAppearance="@style/TextAppearance.AppCompat.Body2" />
请记住使用应用程序而不是android名称空间。尝试使用liatview或recycler视图创建左抽屉。编写自定义适配器,在其中可以轻松地更新任何需要的内容。您只需更改通过适配器传递到listview或recycler视图的数据,并查看其更新 你检查一下。使用自定义列表项设计并使用ListView/RecyclerView,而不是菜单。检查
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textAppearance="@style/TextAppearance.AppCompat.Body2" />
<item
...
app:actionLayout="@layout/menu_counter" />