I am creating an App with a Navigation Draw Activity. In android studio, after I start a new android activity project, I select Navigation draw activity. My question is, how to a change the background color of the navigation draw activity? Right now, the top part is green but the white part where the text and icons are is white and I want to change this white part to dark grey with white text.
Thanks.
Rob
Go to res -> layout -> activity_main.xml and add the following:
<android.support.design.widget.NavigationView
app:itemTextColor="#A9A9A9" // text color
android:background="#FF0000" /> // background color
The top part it is defined in res -> layout -> nav_header_main.xml and the same color definitions apply to it too. Look for :
<LinearLayout android:background="#drawable/side_nav_bar" />
and change it to any color you want.
I just made some changes.
To define the color there are two ways to use the colors file in the values directory or define in hexadecimal as for example android: background = "# 84FFFF".
<android.support.design.widget.NavigationView
android:id="#+id/ejemplo_nav_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/ejemplo_nav_header"
app:menu="#menu/ejemplo_drawer_view"
android:background="#color/color_define"/>
Related
sorry for my bad English.
I have a navigation drawer in some activities, I want the icon of each navigation view item to be placed to the right of that item's text and the whole item get right gravity.
Because I only used Persian in my app, I can not use "supportsRtl" in my code, if I use, it will look weird when I set device language to any rtl languages.
I think probably I can fix this with setting custom layout for navigation view, but I'm looking for a simpler way. this is my NavigationView XML code:
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:menu="#menu/menu"
android:layout_gravity="end" />
Edited :
layoutDirection is a good answer but i used drawerLayout.openDrawer(GravityCompat.START);
for opening navigation drawer. now if device language be an rtl language this make app crash.
Make supportsRtl true and set the layout dirction to RTL on navigation View and LTR in other layouts
Just add android:layoutDirection="rtl" to your NavigationView, like this:
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:menu="#menu/menu"
android:layoutDirection="rtl"
android:layout_gravity="end" />
I have a multi pane view: much like this:
The way I got this is by using elevation:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="4dp"
android:background="#android:color/white">
That scroll view is the detail view on the right. Android is assigned a darker background on my list view on the left to 'show' the elevation. Which is great, view looks perfect. However I want to highlight the selected item in the list.
List View:
Selected state:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/some_color" android:state_activated="true"/>
</selector>
My problem is I need to define some color and I want to make it a little darker than the color of the items in the list. However I am not 100% sure what that color really is.
Can I find that by debugging? Or better yet does anyone know what elevation is really doing to that views color?
Android isn't actually coloring the background differently based on elevation; the only effect an elevation attribute has is showing a shadow on 5.x devices. It just looks darker because you gave the ScrollView a white background and the default background of an Activity is an off-white color. If you want to determine that color, I'd recommend simply taking a screenshot and using an app to see what color those pixels are; I find Color Picker works very well. If you want that background color to be consistent everywhere, I'd manually set your ListView's background to that color.
I am trying a prototype app with SlidingPaneLayout. My SlidingPaneLayout is gray and body view is pure white.
but when i slide in, the small visible area of body page goes slightly dark or overlaying with dark screening. all i want is pure original white color of that body view.
I tried couple of Methods to switch off these but seems impossible. such as
SlidingPaneLayout sp = (SlidingPaneLayout) findViewById(R.id.mainSlider);
sp.setHorizontalFadingEdgeEnabled(false);
or following property in XML
<android.support.v4.widget.SlidingPaneLayout
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:id="#+id/mainSlider"
android:requiresFadingEdge="none" <!-- try one -->
android:fadingEdgeLength="0dp" <!-- try two -->
android:fadingEdge="none" <!-- try three -->
tools:context=".MainActivity">
Any one of you, have you ever done this successfully?
You can set the fade color to transparent:
SlidingPaneLayout sp = (SlidingPaneLayout) findViewById(R.id.mainSlider);
sp.setSliderFadeColor(getResources().getColor(android.R.color.transparent));
I want to make an iOS 7 like drawer that I can slide from the bottom that doesn't cover the full screen and is semi transparent/blurred on Android.
I had a look at SlidingDrawer on android to try and get a start but it looks like its being depreciated. How can I create a similar future proof effect on android?
Just change the background color of the List view that gets populated in navigation drawer fragment.
use of background color "#22FFFFFF" makes navigation drawer semitransparent
Use an hexadecimal color code, which consists of two digits for alpha and six for the color itself, like this:
use android:background ="#88676767" change the first 88 to your selection of opacity
android:background="#c0000000" -for more darkness
Please rate it if it turns helpful.
<ListView 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:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#22FFFFFF"
tools:context="com.Navigation Drawer Fragment" />
I'm just starting out in Android and was making a splash screen. I tried to change the default background colour to grey, but apparently I can't use the same attribute twice. How can I add a background image and change the background colour? Thanks.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/reddit_alien"
android:background="#color/grey"
>
</LinearLayout>
One way to do this, which would be to use 2 layouts.. The outer one having a background of the color and the inner one having the image as the background.
Alternatively you could use a layer list drawable resource file in xml which defines one layer as being the background color and another as the background image. see here: http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList
No that's not possible to declare same property twice. Either she them image as background or color.If you want to set the color and background image then create two views. Set the bottom view background to color or image and set the top view background to color or image.