簡體   English   中英

導航抽屜中的用戶帳戶

[英]User Accounts in Navigation Drawer

我已經使用新的設計支持庫成功設置了導航抽屜,但不確定如何繼續操作。 我需要提供用戶帳戶,有人可以提供代碼或有關如何執行此操作的想法。

導航抽屜

這是我目前擁有的代碼。

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

<RelativeLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <include
        android:id="@+id/app_bar"
        layout="@layout/app_bar" />

</RelativeLayout>


<android.support.design.widget.NavigationView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/header"
    app:menu="@menu/nav_menu" />

假設您已設置SQLite幫助器類( 示例 ),並且具有使用HashMap獲取用戶詳細信息的知識,則可以通過在導航抽屜xml上添加幾個視圖來輕松完成此操作。

您需要從hdondenhof添加文本視圖和circleimageview ,以顯示您的用戶名和個人資料圖片。 而且,如果您希望顯示更多視圖,也可以這樣做。 為它們分配ID,以便可以在其Java對應項上顯示所需的信息。

在導航抽屜片段中,如果用戶名和圖片參數已經存儲在SQLite數據庫中,則可以在此處傳遞用戶名和圖片參數。 就我而言,我通常會在片段的onCreateView中調用它:

// Initialize and declare SQLite handler class to retrieve user's details:
final SQLiteHandler sqLiteHandler = new SQLiteHandler(getActivity());
final HashMap<String, String> user = sqLiteHandler.getUserDetails();

// Retrieving the user's username for display on navUsername
String setUsername = user.get("username");
navUsername = (TextView) view.findViewById(R.id.nav_username);
navUsername.setText("Welcome, " + setUsername);

真的就是那么容易。 circleimageview的工作方式與imageview一樣,因此您可以從數據庫中獲取用戶的圖片,如果找不到圖片,則顯示可繪制的圖片。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM