2015-12-08 77 views
0

我正在處理導航抽屜,我想在導航抽屜中顯示用戶的詳細信息,如個人資料,聯繫我們,註銷等,如果他沒有登錄,那麼我想只顯示一個項目這是已經在其上登錄閒來無事必須顯示在它,我將使用JSON用於身份驗證的登錄請參考圖片的朋友從導航抽屜1登錄

First image without Logged in

After logged In

+0

投票決定關閉,因爲這個問題太寬泛。 – Skynet

回答

1

你的問題很廣。但是,要達到您想要的效果,您可能需要使用MaterialDrawer庫。只需檢查他們的自述文件,它使用起來非常簡單。

「登錄」功能,您正在尋找將在你的抽屜AccountHeader,例如:

// Create the AccountHeader 
AccountHeader headerResult = new AccountHeaderBuilder() 
    .withActivity(this) 
    .withHeaderBackground(R.drawable.header) 
    .addProfiles(
     new ProfileDrawerItem().withName("Mike Penz").withEmail("[email protected]").withIcon(getResources().getDrawable(R.drawable.profile)) 
    ) 
    .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() { 
     @Override 
     public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) { 
      return false; 
     } 
    }) 
    .build(); 

//Now create your drawer and pass the AccountHeader.Result 
new DrawerBuilder() 
    .withAccountHeader(headerResult) 
    //additional Drawer setup as shown above 
    ... 
    .build(); 

(從官方README拍攝片段,再次:每一件事情是there)。

+0

我也想通過使用JSONS來實現它 –

+0

這將是一個完全獨立的問題,然後:http://developer.android.com/reference/android/util/JsonReader.html我鼓勵你編輯你的主要問題提供更多細節。 –

0

你的問題很廣,但如果你使用的是導航視圖中,可以使用由機器人提供

 navigationView.inflateHeaderView(layoutResId); 
     navigationView.inflateMenu(menuResId); 

導航視圖更改標題視圖和抽屜的項目。所以它不是第三方庫,集成起來很簡單。

 <android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true"> 

    <!-- your content layout --> 

    <android.support.design.widget.NavigationView 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      app:headerLayout="@layout/drawer_header" 
      app:menu="@menu/drawer"/> 
    </android.support.v4.widget.DrawerLayout> 

你可以在這裏找到完整的信息 - http://android-developers.blogspot.in/2015/05/android-design-support-library.html

http://developer.android.com/reference/android/support/design/widget/NavigationView.html

+0

是的,我正在使用導航視圖 –

+0

我的想法是if(islogged == true){navigationView.inflateHeaderView(layoutResId); navigationView.inflateMenu(menuResId); else {navigationView.inflateHeaderView(layoutResId); navigationView.inflateMenu(menuResId);} –

+0

是的,當然,你必須檢查用戶是否已登錄 – Ishan