問題描述
我希望在我的導(dǎo)航抽屜中的項(xiàng)目旁邊有圖標(biāo),我設(shè)置如下:
I would like to have icons next to my items in my navigation drawer that I have set up like this:
Titles = getResources().getStringArray(R.array.array1);
Icons = getResources().getIntArray(R.array.icons);
mDrawerLayout = (DrawerLayout)findViewById(R.id.Welcome);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerList.setAdapter( new ArrayAdapter<String>(this, R.layout.drawer_list_item, Titles));
我知道該過程必須涉及將圖像視圖添加到位于抽屜列表項(xiàng)的 XML 中的文本視圖中,但我不知道該怎么做.實(shí)現(xiàn)這一目標(biāo)的最佳方法是什么?
I know that the process must involve adding an image view to the text view that is in the XML for the drawer_list_item but I'm not sure how to do that. What is the best way to accomplish this?
這是我的drawer_list_item.xml:
This is my drawer_list_item.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="#111"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
推薦答案
導(dǎo)航抽屜本質(zhì)上是一個(gè)列表視圖.使用您想要的任何布局(文本+圖像視圖)創(chuàng)建一個(gè)drawer_item.xml,并將其傳遞給arrayAdapter.然后在填充 listView 時(shí)(在 getview 方法中),將 imageView 分配給您選擇的可繪制對(duì)象.
The Navigation Drawer is essentially a list view. Create a drawer_item.xml with whatever layout you want (text+imageview) and pass it to the arrayAdapter. Then when populating the listView (in the getview method), assign the imageView to the drawable of your choosing.
這篇關(guān)于如何將圖標(biāo)添加到導(dǎo)航抽屜中的項(xiàng)目的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!