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

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

Related

Why the layout_below is invalid that running on the phone?

This is my layout. My question is that the id is "below_button" LinearLayout is invalid that running on the phone. The phone didn’t display this LinearLayout, but others layout is right. How come?
<?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">
<include
android:id="#+id/title"
layout="#layout/toptitlebar" />
<LinearLayout
android:id="#+id/query_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/title"
android:background="#e2dfdf"
android:layout_alignParentLeft="true">
<EditText
android:id="#+id/ram_assistinqnum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="0.45"
android:hint="通知书编号"
android:maxLines="1"
/>
<TextView
android:id="#+id/ram_operate_date"
style="#style/SpinnerCtl_Wrap"
android:gravity="center"
android:layout_margin="10dp"
android:layout_weight="0.45"
android:hint="操作时间"
android:textColor="#color/black"/>
<ImageView
android:id="#+id/ram_query"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.1"
android:src="#drawable/ram_query"
android:layout_margin="10dp"/>
</LinearLayout>
<com.sdrcu.operatingdecisions.view.scrollabletbv.ScrollTableView4
android:id="#+id/scrollTableView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/query_detail"
/>
<LinearLayout
android:id="#+id/below_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#e2dfdf"
android:layout_below="#+id/scrollTableView"
>
<ImageView
android:id="#+id/ram_arrow_previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:layout_weight="0.3"
android:src="#drawable/ram_arrow_previous"/>
<TextView
android:id="#+id/paging"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:text="翻页"
android:textColor="#color/text_blue"
android:textSize="20sp"
/>
<ImageView
android:id="#+id/ram_arrow_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:layout_weight="0.3"
android:src="#drawable/ram_arrow_next"/>
<ImageView
android:id="#+id/ram_agree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:src="#drawable/ram_agree"/>
<ImageView
android:id="#+id/ram_disagree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:src="#drawable/ram_disagree"/>
</LinearLayout>
</RelativeLayout>
#Seal
In my layout editor's Preview I changed the "Theme in Editor" to "Theme"
And I started to get errors like your screenshot.
See:
So, I selected "All" -> "AppTheme" from the "Theme in Editor" option... Do not forget to press "Ok"
And the errors went away:
So, why do not you also try to set it to "All" -> "AppTheme"
Further it appears to me that you might have created style(s) which do not inherit from "proper parent".
Using below example: "AppTheme" inherits all the required attributes from "Theme.AppCompat.Light.DarkActionBar". And thus, you need to only specify the attributes you need modified.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
...
<item name="colorAccent">#color/colorAccent</item>
...
</style>
replace
android:layout_below="#id/query_detail"
in
<com.sdrcu.operatingdecisions.view.scrollabletbv.ScrollTableView4
android:id="#+id/scrollTableView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/query_detail"
/>
with
android:layout_below="#+id/query_detail"
yes you miss the parameter height and weight
android:layout_width="match_parent"
android:layout_height="wrap_content"
add in your layout it works Use the Tag

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>

ProgressBar not displaying

I have an app where I have used ProgressBar in several places.
<ProgressBar
android:id="#+id/pb_loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="visible"/>
All the progressbars are not appearing in any activity.
I have tried all solutions by changing the color of the progressbar programmatically and by adding an xml drawable, but its not working.
Below is my styles.xml
<style name="MyAppCompatTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary">#FFFFFF</item>
<item name="android:colorPrimaryDark">#F1F1F1</item>
<item name="android:colorAccent">#EF5350</item>
</style>
Technically the progressbar should take the colorAccent, but its not appearing at all.
Posting a sample view:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/logo"
android:src="#drawable/app_icon"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/logo"
android:textSize="18sp"
android:id="#+id/subtitle"
android:textColor="#color/secondary_text"
android:layout_marginTop="30dp"
android:text="QUICK BROWN FOX"/>
<ProgressBar
android:id="#+id/pb_loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="visible"/>
The progressbar is not overlapped by any view in any activity of the app. I dont have any other theme in my styles.xml and I am not overriding the activity theme in the manifest also. Its an application level default theme.
Even if i create a new activity with only a progressbar, it doesnt appear.
It is weird as in all the activity design previews, the progress bar appears properly but on running the app it doesnt.
Please let me know if some other info is required.
I was too facing same problem, may its there but hiding because of other views. what i did in your case would minor change in xml file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="#+id/pb_loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="visible"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/logo"
android:src="#drawable/app_icon"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/logo"
android:textSize="18sp"
android:id="#+id/subtitle"
android:textColor="#color/secondary_text"
android:layout_marginTop="30dp"
android:text="QUICK BROWN FOX"/>
exactly nothing but progress bar on top of other, this work for me i don't know why.

Changing navigationView header text color

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:

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