Changing navigationView header text color - android

How do you change the header text colors in navigation Drawer. I am using the latest support design library. Image is attached below.

I had a similar problem with group title color and I found the solution.
Just put it into style.xml main theme.
<item name="android:textColorSecondary">#FFFFFF</item>
No need to modify your parent theme.

Just changing the parent theme from Theme.Appcombat.Light.ActionBar to Theme.AppCombat solves it.

Assuming you created it with a separate header xml file
<?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="178dp"
android:background="#drawable/background_poly"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:textColor="#ffffff"
android:text="Akash Bangad"
android:textSize="14sp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:layout_marginLeft="16dp"
android:layout_marginTop="5dp"
android:text="akash.bangad93#gmail.com"
android:textSize="14sp"
android:textStyle="normal"
/>
</LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/aka"
android:layout_marginLeft="16dp"
android:layout_marginTop="38dp"
android:id="#+id/circleView"
/>
</RelativeLayout>
Just Change the background color of the relative layout
Here is the link I used
http://www.android4devs.com/2014/12/how-to-make-material-design-navigation-drawer.html?m=1

Currently in the Material Components Library it is based on the android:textColorSecondary color.
You can override this color only in the NavigationView using:
<com.google.android.material.navigation.NavigationView
android:theme="#style/ThemeOverlay.myCustomTitle"
..>
with:
<style name="ThemeOverlay.myCustomTitle" parent="">
<item name="android:textColorSecondary">#color/....</item>
</style>
Final result:

Related

Android: Custom Spinner without selector

i tried to change the dropdownlabel / selector of a AndroidAppCombatSpinner before but did not really get useful help see: Make Drowdown label smaller.
So now I am wondering if it is possible to make a Spinner without a dropdown label.
See the Screenshot for what I want to do:
Edit: Added my XML file which is getting inflated:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="horizontal"
android:background="#drawable/x_linearlayoutcontainer_inside"
>
<ImageView
android:id="#+id/ivSpinnerImage"
android:layout_marginTop="3dp"
android:layout_marginRight="3dp"
android:layout_marginBottom="3dp"
android:layout_width="0dp"
android:layout_height="29dp"
android:layout_weight="2.5"
android:cropToPadding="true"
android:scaleType="fitCenter"
android:src="#drawable/blue"
/>
<TextView
android:id="#+id/tvSpinnerText"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="7.5"
android:gravity="center"
android:padding="5dp"
android:text="Accessory"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="15sp"
android:textColor="#fff"
/>
</LinearLayout>
Thanks guys for any suggestions!
try to change the style of your spinner to this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style parent="#android:style/Widget.Spinner" name="SpinnerwithNoArrow">
<item name="android:background">#android:drawable/edit_text</item>
</style>
</resources>

Custom dialog becomes the size of the first control in android

I have the following layout for my custom log in dialog
<?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="match_parent"
android:padding="#dimen/padding_large">
<ImageButton android:src="#drawable/ic_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/dialog.login.settings"
android:padding="#dimen/margin_medium" />
<TextView android:text="#string/dialog.login.text.user_name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/dialog.login.user_name"
android:layout_width="match_parent"
android:gravity="center"
android:ems="20"
android:layout_height="wrap_content"
android:inputType="text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView android:text="#string/dialog.login.text.password"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/dialog.login.password"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox android:id="#+id/dialog.login.show_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/dialog.login.check.show_password"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_margin="#dimen/margin_medium"
android:checked="false" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:id="#+id/dialog.login.cancel"
android:drawableStart="#drawable/ic_exit_black"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_medium"
android:text="#string/dialog.login.button.cancel" />
<Button android:id="#+id/dialog.login.connect"
android:text="#string/dialog.login.button.connect"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_marginStart="#dimen/margin_medium"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
when I create the dialog and setcontentview the width of the dialog becomes equal to that of the image button on the first row
if I remove that , it becomes the size of the EditText (dialog.login.user_name) whose ems is 20
when I make the dialog's constructor call the base dialog constructor with a theme of R.style.Theme.Material.Dialog it does get the correct (about 3/4 of the screen) but the problem is that it ignores my primary and accent colours (which is normal)
Is there a way to have the dialog have the Theme.Material.Dialog size but still keep my own primary/accent colours?
thanks in advance for any help you can provide
After a lot of searching it seems that the solution is to actually replace the dialogTheme attribute of my main theme, so the solution was:
<style name="app.theme"
parent="android:Theme.Material.Light.NoActionBar.Fullscreen">
<item name="android:dialogTheme">#style/app.dialog</item>
......
</style>
<style name="app.dialog"
parent="android:Theme.Material.Light.Dialog">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary.dark</item>
<item name="android:colorAccent">#color/accent</item>
</style>

How to Remove left space on custom tool bar in android

I have created custom tool bar in my android application.In my application,when I see layout is showing correct but when run application then show more margin from left side.I am extend AppCompatActivity in my Activity.
I have use following code for custom toolbar and XML
Code
ActionBar actionBar = getSupportActionBar();
// add the custom view to the action bar
actionBar.setCustomView(R.layout.custom_actionbar);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/nav_headerbg" >
<ImageButton
android:id="#+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:background="#drawable/backbtn"
android:contentDescription="#string/clear" />
<ImageButton
android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/btnBack"
android:background="#drawable/ico_nav"
android:contentDescription="#string/clear" />
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Setting"
android:textColor="#fff"
android:textSize="20sp" />
<ImageButton
android:id="#+id/btnDeviceList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="1dp"
android:padding="5dp"
android:background="#drawable/headerdevicelist"
android:contentDescription="#string/clear" />
</RelativeLayout>
Please find attached image.I want to remove left space which is marked by red.How to fixed it and suggest me.
Add custom actionbar style in your app:
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar">
<item name="contentInsetStart">0dp</item>
<item name="contentInsetEnd">0dp</item>
</style>
and set it in your application theme:
<style (your application theme)>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>

Android : Padding is gone when android:fitsSystemWindows is true - Lollipop

Here is my layout.xml for splash screen.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/holo_orange_light"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:paddingBottom="#dimen/splash_padding_bottom"
android:paddingLeft="#dimen/splash_padding_left"
android:paddingRight="#dimen/splash_padding_right"
android:paddingTop="#dimen/splash_padding_top">
<LinearLayout
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/title"
android:textSize="#dimen/splash_title"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/app_name"
/>
<TextView
android:textColor="#android:color/white"
android:textSize="#dimen/splash_greetings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Hi\nthere,\ngood\nevening!"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</LinearLayout>
</RelativeLayout>
and styles.xml (values-v21)
<resources>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
Now, when I ran the app on kitkat the splash screen was getting displayed properly but when I ran it on Lollipop all the padding I have given to RelativeLayout was gone.
What I am doing wrong?
This is the normal behavior, padding top and padding bottom are overwritten by the android:fitsSystemWindows="true".
You can find more by reading Ian Lake's Medium post on fitsSystemWindows:
https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec#.nljqv5yh8
Try adding android:margin instead

How to center a RatingBar in Android

I have created a custom RatingBar as described in one of the tutorials given here on stack-overflow and it's looking great, the problem is with the centering of the image. here is what I've got:
As you can see the TextView is centered vertically in the LinearLayout, but the RatingBar is at the top of it. Here is my xml code of this image:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:foregroundGravity="center" >
<LinearLayout
android:layout_width="320dp"
android:layout_height="match_parent"
android:gravity="center" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<RatingBar
android:id="#+id/ratingBar1"
style="#style/starsRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:numStars="5"
android:rating="2.3"
android:stepSize="1" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</ScrollView>
Here is the code of the styling:
<style name="starsRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/star_ratingbar_full</item>
<item name="android:minHeight">36dip</item>
<item name="android:maxHeight">36dip</item>
</style>
Any ideas in the RatingBar would be apprisiated!
THANKS
Ok, I think I've got it.
The key issue is the ScrollView: it automatically makes things compact, unless you specifically tell it otherwise. In the scroll view, set
android:fillViewport="true"
to make it use the space available.
Hello to get all items at top you have to put:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:text="TextView" />
instead of:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
if you just want the rating bar centred:
just remove style="#style/starsRatingBar"
EDIT:
forget any think I said befor, it seems to work better when I changed the style to : (adjust your min/max height to get "perfect result" )
<style name="starsRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#android:drawable/star_on</item>
<item name="android:minHeight">26dip</item>
<item name="android:maxHeight">26dip</item>
</style>

Categories

Resources