Text won't appear in TextView - android

I am making a Navigation Drawer in my Android app. The Navigation Drawer has an Header which includes a Account Icon and a Text View. But when I run the App, I can no longer see the Icon or the TextView.
This is what I have been getting,
Here is my code for my navigation drawer activity_admin.xml
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.vishistvarugeese.ongc_app.AdminActivity">
<android.support.design.widget.NavigationView
app:headerLayout="#layout/admin_nav_header"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#color/white"
app:itemIconTint="#color/black"
app:itemTextColor="#color/colorAccent"
app:menu="#menu/admin_menu"
android:layout_gravity="start"
app:theme="#style/menu_style">
</android.support.design.widget.NavigationView>
This is the code for my navigation header, admin_nav_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#drawable/headernav"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/ic_account_circle_white_48dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/navUserName"
android:text="#string/name"
android:textStyle="bold"
android:textColor="#color/white"
android:layout_marginTop="10dp"/>
</LinearLayout>
This is what I was trying to do
Can someone please help me with the issue?

Remove theme and other property from NavigationView.
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/homeDrawerColor"
android:fitsSystemWindows="true"
app:headerLayout="#layout/admin_nav_header"
app:menu="#menu/admin_menu" />
If not work then give a direct string to check any problem in string.xml or not...

Related

Customize TextView to look like Menu Item

I am trying to specify my own Android Navigation Drawer.
There is dynamic data shown so I can't just set it up in a menu.xml.
Right now I am trying to customize the look of a TextView into my ListView to look pretty much like a Menu Item but these classes are all abstract. Furthermore I was not able to find something usefull at the material.io.
What I am looking for:
What I got right now:
Here is the corresponding XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".SlideshowActivity"
android:id="#+id/drawer_slide_show">
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
tools:context=".SlideshowActivity">
<android.support.design.widget.FloatingActionButton
android:id="#+id/floatingActionButtonRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_marginRight="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_arrow_right"
android:alpha="0.5" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/floatingActionButtonLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_marginLeft="8dp"
android:alpha="0.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_arrow_left" />
<android.support.v4.view.ViewPager
android:id="#+id/viewPager_slideshow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent">
</android.support.v4.view.ViewPager>
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigationView_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white">
<ListView
android:id="#+id/listView_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:dividerHeight="5px"
android:listSelector="#drawable/ic_media_pause_dark" >
</ListView>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
You need to Customize the navigation drawer by using the listview with custom Adapter.Here is example of Custom navigation drawer.

Spinner can be clicked on top of Navigation menu

I have a navigation menu with some items. The problem that I am facing is the Spinner items and other UI elements which is underneath the menu when it is open remains clickable even when the menu is on top of those, as explained in the figure.
Here is my activity layout files.(activity_main.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">
<Spinner
android:id="#+id/delivery_area_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="#android:color/transparent"
android:gravity="center"
android:spinnerMode="dropdown" />
<include layout="#layout/layout_drawer_navigation" />
</RelativeLayout>
This is my navigation drawer layout.
<?xml version="1.0" encoding="utf-8"?>
<merge 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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true">
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/layout_main_navigation_header"
app:menu="#menu/main_drawer_menu" />
</android.support.v4.widget.DrawerLayout>
I tried to look for solutions and found that for many people setting android:clickable="true" does the trick but in my case that is also not working.'

Android studio navigation drawer not fitting correctly

I've thoroughly searched but couldn't find my answer, sorry if this a stupid post.
My navigation drawer won't set when I declare android:layout_gravity="start" I've been trying to solve this issue however I cannot find it anywhere online. I was wondering if anyone could point me in the right direction. Here is a screenshot of what it navigation drawer looks like on a S7 device.
https://i.stack.imgur.com/OL8re.png
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/activity_homepage"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="mypackagename.homepage">
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="#menu/navigation_menu"
app:headerLayout="#layout/navigation_header"
android:layout_gravity="start">
</android.support.design.widget.NavigationView>
<include layout="#layout/navigation_action">
</include>
<Button
android:text="Add a post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="74dp"
android:id="#+id/addNewPost"
android:onClick="addNewPost"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<include layout="#layout/main_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</include>

NavigationView headerlayout not scrolling

I have simple question! I am stuck on it. I have seen plenty of answers and tried everything that I can.
Here is my DrawerLayout:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".BaseNavDrawerActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<include
android:id="#+id/toolbar"
layout="#layout/layout_toolbar" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_drawer_header_layout"
app:itemBackground="#color/white"
app:itemTextColor="#color/nav_text_color_selector"
app:itemIconTint="#color/nav_text_color_selector"
app:menu="#menu/nav_drawer" />
</android.support.v4.widget.DrawerLayout>
And this is my nav_drawer_header_layout:
<?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="200dp"
android:gravity="bottom"
android:background="#drawable/drawer_cover">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/google_logo"
android:id="#+id/image_account"
android:scaleType="centerCrop"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="17dp" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinner_accounts_list"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:spinnerMode="dropdown"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:layout_marginEnd="22dp"
android:layout_marginRight="22dp" />
</RelativeLayout>
When I scroll NavigationDrawer, only NavigationView get scrolled but headerlayout(nav_drawer_header_layout) remains still and doesn't scroll at all.
I know DrawerLayout scrolls completely but I am stuck here.
What I am doing wrong?
EDIT-1
Java code snippet:
mNavViewHeaderLayout = LayoutInflater.from(EmailActivity.this).inflate(R.layout.nav_drawer_header_layout, mNavigationView);
mSpinnerAccounts = (Spinner)mNavViewHeaderLayout.findViewById(R.id.spinner_accounts_list);
You need to do two things.
remove app:headerLayout="#layout/nav_drawer_header_layout" from your NavigationView.
Inflate header in your navigation view at run time.
View headerLayout = navigationView.inflateHeaderView(R.layout.nav_header_home);
TextView txtContact = (TextView) headerLayout.findViewById(R.id.txtContact);
TextView txtHeaderLogoName = (TextView) headerLayout.findViewById(R.id.txtHeaderLogoName);

Play video upon a Fragment but below Navigation Drawer

I am trying to write a simple code to play video form raw folder and I have to play video on fragment but my activity has a navigation drawer so when I have tried to play this video at first time there is only voice no video so I search for this problem then I got a solution videoView.setZOrderOnTop(true) but now there is another issue I faced that is the video window comes upon the navigation drawer.this is the screen shot what is happing
hear is my xml layouts
This is for activity
<?xml version="1.0" encoding="utf-8"?>
<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" tools:openDrawer="start">
<include layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer"
style="#style/textDisply2.title"
>
<TextView
android:id="#+id/nav_call_sleep_care"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:background="#color/buttonColor"
android:gravity="center"
android:drawablePadding="#dimen/column_padding"
android:drawableLeft="#mipmap/call_care_small"
android:textColor="#android:color/black"
android:textSize="#dimen/home_wh_btn_txt"
android:text="#string/call_sleep_care" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
and This is my fragment layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
>
<TextView
android:id="#+id/screen_name"
android:text="#string/video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="#style/TextAppearance.AppCompat.Title"
/>
<LinearLayout
android:layout_below="#+id/screen_name"
android:id="#+id/video_dis_box"
android:layout_marginTop="50dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/play_video_btn"
android:layout_width="#dimen/img_btn_height_play"
android:layout_height="#dimen/img_btn_width_play"
android:src="#mipmap/music"
/>
<LinearLayout
android:padding="#dimen/column_padding"
android:orientation="vertical"
android:layout_weight="1"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/video_title"
android:text="#string/video_title"
style="#style/textDisply2.subHead"
/>
<TextView
android:id="#+id/dr_surendra"
android:text="#string/dr_surendra"
style="#style/textDisply2.subHead"
android:textSize="#dimen/home_color_btn_txt"
/>
</LinearLayout>
<ImageView
android:id="#+id/lock"
android:layout_width="#dimen/img_btn_height_lock"
android:layout_height="#dimen/img_btn_width_lock"
android:src="#mipmap/lock"
/>
</LinearLayout>
<VideoView
android:layout_below="#+id/video_dis_box"
android:id="#+id/play_video"
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
please suggest me the solution.
I think that to invoke videoView.setZOrderOnTop(true) is non-sense.
What I think you have better to do is to close the Navigation Drawer.
So somewhere in your code for example:
DrawerLayout drawerLayout = (DrawerLayout) findViewById(drawer_layout);
NavigationView navigationView = (NavagationView) findViewById(nav_view);
drawerLayout.closeDrawer(navigationView);
will close the Drawer and the VideoView won't be hidden.
Note: the code to close the Drawer may differ depends on your situation.

Categories

Resources