【问题标题】:Fetching email from shared preferences inside NavaigationDrawer从 NavaigationDrawer 中的共享首选项中获取电子邮件
【发布时间】:2016-01-11 18:21:18
【问题描述】:

我正在关注导航抽屉的 android 教程,但我无法在导航标题中显示图像

http://www.android4devs.com/2014/12/how-to-make-material-design-navigation-drawer.html/ 如何在导航抽屉中添加个人资料图片和电子邮件地址? 下面是导航页眉

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="178dp"
    android:background="#FF00CC"
    android:weightSum="1">

    <LinearLayout android:layout_width="wrap_content"
                  android:layout_height="56dp"
                  android:layout_alignParentBottom="true"
                  android:layout_alignParentLeft="true"
                  android:layout_alignParentStart="true"
                  android:orientation="vertical">

                  <!-- Name-->
        <TextView
            android:id="@+id/usernameprofile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:textColor="@color/white"
            android:textSize="16sp"
            android:textStyle="bold"/>

        <TextView
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="kevin@gmail.com"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="5dp"
            android:textColor="@color/white"
            android:textSize="16dp"
            android:textStyle="normal"/>
        </LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
    android:layout_width="70dp"
    android:src="@drawable/profile_sample"
    android:layout_height="70dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="38dp"
    android:id="@+id/circleView"/>

</RelativeLayout>

【问题讨论】:

    标签: java android android-layout android-fragments android-activity


    【解决方案1】:

    导航抽屉 header.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/profile_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:background="@mipmap/profile"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="15dp" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="abc@gmai.com"
        android:textSize="14sp"
        android:textColor="#FFF"
        android:textStyle="bold"
        android:paddingBottom="4dp"
        android:id="@+id/username"
        android:layout_alignTop="@+id/profile_image"
        android:layout_toRightOf="@+id/profile_image"
        android:layout_toEndOf="@+id/profile_image"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="25dp" />
    </RelativeLayout>
    

    导航抽屉所在的主屏幕

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:id="@+id/main_layout"
        android:layout_centerVertical="true"
        tools:ignore="ContentDescription"
        android:layout_height="match_parent"
        tools:context="com.uowd.sport.app.MainScreen">
     <android.support.v4.widget.DrawerLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/drawer_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    <android.support.design.widget.NavigationView
                android:id="@+id/nav_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:dividerHeight="0dp"
                android:background="#004f71"
                android:divider="@android:color/transparent"
                android:choiceMode="singleChoice"
                android:fitsSystemWindows="true">
            <include
                layout="@layout/header.xml"
                android:id="@+id/left_drawer"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            </android.support.design.widget.NavigationView>
    
        </android.support.v4.widget.DrawerLayout>
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多