1
圖片瀏覽和文本這是我的菜單項:如何設置菜單項
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="">
<menu>
<item android:title="" />
<item android:title="" />
</menu>
</item>
<item
android:id="@+id/nav_item_inbox"
android:icon="@drawable/inbox"
android:title="Inbox" />
<item
android:id="@+id/nav_item_sent"
android:icon="@drawable/sent"
android:title="Sent" />
<item
android:id="@+id/nav_item_draft"
android:icon="@drawable/draft"
android:title="Drafts" />
<item android:title="Others">
<menu>
<item
android:icon="@drawable/spam"
android:title="Spam" />
<item
android:icon="@drawable/bin"
android:title="Bin" />
</menu>
</item>
<group android:id="@+id/group_settings_id">
<item
android:icon="@drawable/settings"
android:title="Settings" />
<item
android:icon="@drawable/help"
android:title="Help" />
</group>
</menu>
這是我的課:
public class MainActivity extends AppCompatActivity{
DrawerLayout mDrawerLayout;
NavigationView mNavigationView;
FragmentManager mFragmentManager;
FragmentTransaction mFragmentTransaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/**
*Setup the DrawerLayout and NavigationView
*/
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mNavigationView = (NavigationView) findViewById(R.id.shitstuff) ;
/**
* Lets inflate the very first fragment
* Here , we are inflating the TabFragment as the first Fragment
*/
mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();
/**
* Setup click events on the Navigation View Items.
*/
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
mDrawerLayout.closeDrawers();
if (menuItem.getItemId() == R.id.nav_item_sent) {
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.containerView,new SentFragment()).commit();
}
if(menuItem.getItemId()==R.id.nav_item_draft)
{
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.containerView,new Fourthfragment()).commit();
}
if (menuItem.getItemId() == R.id.nav_item_inbox) {
FragmentTransaction xfragmentTransaction = mFragmentManager.beginTransaction();
xfragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();
}
return false;
}
});
/**
* Setup Drawer Toggle of the Toolbar
*/
android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, toolbar,R.string.app_name,
R.string.app_name);
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
}
}
我要添加圖像和文本查看在Navigaition菜單項我我無法設置背景顏色和圖像,而我必須設置ImageView以顯示User Pic和TextView以顯示用戶名。
我一定要實現這樣的請幫我,我怎麼會做到這一點請建議。
,我們必須添加這個但是,在我會把圖像視圖 –
你只需要創建的ImageView和文本獨立的佈局和使用,在添加頁眉佈局,以你的
NavigationView
NavigationView。您不必在菜單中添加布局。 僅供參考,你可以檢查以下鏈接: http://www.android4devs.com/2015/06/navigation-view-material-design-support.html –好吧,等待讓我試試我會askk –