When setting RatingBar in xml file and set android:drawableProgress to custom drawable I've created (as described here) it shows 5 stars in the preview screen of android studio with api 22 but when I set the api target to api 23 it shows 1 star but the ratingbar (android:width="wrap_content") is at the same width as it is with 5 stars. This is also checked on cellular phones with Lollipop and marshmallow OS (Same behavior as described).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/spacing_standard"
android:orientation="vertical"
android:background="#color/sfly_orange"
android:fillViewport="true">
<com.shutterfly.android.commons.common.ui.TypefacedTextView
android:id="#+id/thank_you_label_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/order_confirmation_thank_you"
android:textColor="#android:color/white"
android:textSize="#dimen/rate_app_text_size_largest"
android:gravity="center"
app:typeface="medium"
android:layout_marginTop="#dimen/spacing_standard"/>
<ImageView
android:layout_width="#dimen/rate_app_image_width"
android:src="#drawable/rate_icon"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/rate_app_spacing_standard"
android:layout_height="#dimen/rate_app_image_height"/>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/rate_app_spacing_standard">
<com.shutterfly.android.commons.common.ui.TypefacedTextView
android:id="#+id/order_number_label_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
app:typeface="medium"
android:text="#string/order_confirmation_order_number_label"
android:textColor="#android:color/white"
android:textSize="#dimen/rate_app_text_size_normal"/>
<com.shutterfly.android.commons.common.ui.TypefacedTextView
android:id="#+id/order_number_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
app:typeface="medium"
android:layout_marginTop="#dimen/spacing_standard"
android:textColor="#android:color/white"
android:textSize="#dimen/rate_app_text_size_larger"/>
<com.shutterfly.android.commons.common.ui.TypefacedTextView
android:id="#+id/order_confirmation_details_label_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/order_confirmation_details_label"
android:layout_marginTop="#dimen/spacing_standard_large"
android:textAlignment="center"
android:lineSpacingExtra="#dimen/rate_app_text_line_spacing"
android:gravity="center"
app:typeface="oblique"
android:textColor="#android:color/white"
android:textSize="#dimen/rate_app_text_size_normal"
tools:ignore="UnusedAttribute"/>
<RatingBar
android:id="#+id/rate_app_rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/rate_app_spacing_standard"
android:numStars="#integer/rating_bar_number_of_stars"
android:stepSize="#integer/rating_bar_step"
android:minHeight="#dimen/button_height"
android:maxHeight="#dimen/button_height"
style="?android:attr/ratingBarStyle"
android:layout_gravity="center"
android:progressDrawable="#drawable/rating_bar_star_style"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_marginTop="#dimen/rate_app_spacing_standard">
<com.shutterfly.android.commons.common.ui.TypefacedTextView
android:id="#+id/rate_app_button"
android:layout_width="#dimen/button_width"
android:layout_height="#dimen/button_height"
android:gravity="center"
android:background="#drawable/button_white_background"
android:paddingLeft="#dimen/spacing_standard"
android:paddingRight="#dimen/spacing_standard"
android:text="#string/rate_shutterfly"
android:textAllCaps="true"
android:textColor="#color/sfly_orange"
android:textSize="#dimen/rate_app_text_size_normal_larger"
app:typeface="medium"/>
<com.shutterfly.android.commons.common.ui.TypefacedButton
android:id="#+id/return_to_store_button"
android:layout_width="#dimen/button_width"
android:layout_height="#dimen/button_height"
android:paddingLeft="#dimen/spacing_standard"
android:layout_marginTop="#dimen/spacing_standard"
android:layout_gravity="bottom|center_horizontal"
android:paddingRight="#dimen/spacing_standard"
android:text="#string/order_confirmation_return_to_store"
style="?android:attr/borderlessButtonStyle"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="#dimen/rate_app_text_size_normal"
app:btnTypeface="medium"
android:layout_marginBottom="#dimen/spacing_standard"
android:background="#drawable/button_orange_background"/>
</LinearLayout>
</LinearLayout>
Maybe the default numStars value has changed.
When I set it in the xml file, it works fine.
<RatingBar
...
numStars="5" />
It could be a layout issue too, if wrap_content doesn't have enough space to display 5 stars. Maybe you have qualifiers for Api 23 ? If not and it works fine for <23, do not mind about it.
You can use custom style as below and use that style in your layout file:
<style name="CustomRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/rating_bar_star_style</item>
<item name="android:minHeight">#dimen/button_height</item>
<item name="android:maxHeight">#dimen/button_height</item>
<item name="android:numStars">#integer/rating_bar_number_of_stars</item>
<item name="android:stepSize">#integer/rating_bar_step</item>
</style>
And use this in your layout as below:
<RatingBar
android:id="#+id/rate_app_rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/rate_app_spacing_standard"
style="#style/CustomRatingBar"
android:layout_gravity="center"/>
I think there is some problem with the theme you are using. Please try AppTheme instead of any other and the above code might work for you.
Related
I decided to add selected option in my TextView, but when it was selected and addition menu pop up - it cut TextView down below.
Before selection:
Before selection:
https://i.stack.imgur.com/9jbMN.png
After selection:
https://i.stack.imgur.com/C3XWh.png
How can I fix it?
activity_main:
<LinearLayout 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="#color/light_yellow"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="#+id/selected_date_field"
style="#style/MainTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="#string/selected_date_field" />
<TextView
android:id="#+id/selected_date"
style="#style/SecondTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/selected_date" />
<TextView
android:id="#+id/in_minutes_field"
style="#style/MainTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textIsSelectable="true"
android:textColorHighlight="#color/blue"
android:text="#string/in_minutes_field" />
<TextView
android:id="#+id/in_minutes_till_date"
style="#style/SecondTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/in_minutes_till_date" />
</LinearLayout>```
you can try app:autoSizeTextType:uniform for that textView.
Note: If you gave already size like "textsize: 15sp" remove that line.
Found out that the problem was due to the fact that in the themes.xml I had the same color in <item name="colorOnPrimary">#color/blue</item> (background) and <item name="colorSecondary">#color/blue</item> (color of handlers), because of it I couldn't see handlers
Thanks everyone!
I've used "com.google.android.material.switchmaterial.SwitchMaterial" in that left margin having some space. How to reduce that?
I've need align straight of the everyone text. I'm not add end margin or padding of the switch, Parent layout margin only I've set. Below my XML code and styles. Please provide your suggestion to reduce that margin, Thanks.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<RelativeLayout
android:id="#+id/who_can"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<com.google.android.material.textview.MaterialTextView
style="#style/TextBlackRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/video_view_result"
android:singleLine="true"
android:text="#string/who_can_view"
android:textSize="#dimen/text_small"
android:visibility="visible" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/video_view_result"
style="#style/TextBlackRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:singleLine="true"
android:text="Everyone"
android:textSize="#dimen/text_small" />
</RelativeLayout>
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="#+id/save_switch"
style="#style/SwitchButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/who_can"
android:checked="true"
android:text="#string/save_gallery"
android:textSize="#dimen/text_small"
app:trackTint="#color/colorSecondaryText" />
</RelativeLayout>
<style name="SwitchButtonStyle" parent="Widget.MaterialComponents.CompoundButton.Switch">
<item name="thumbTint">#drawable/switch_selector</item>
<item name="android:fontFamily">#font/font_regular</item>
<item name="android:textColor">#color/colorBlack</item>
</style>
In your relativeLayout/topRelativeLayout, You added margin. Which means you want to margin from every side. That's why It's happening
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
remove the android:layout_margin="10dp". Add margin_top, margin_right what you wanna do.
You should give wrap content for switch width , or make it inside a new Relative layout
if your end margin is showing after removing from
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
then
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="#+id/save_switch"
style="#style/SwitchButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/who_can"
android:checked="true"
android:text="#string/save_gallery"
android:textSize="#dimen/text_small"
app:trackTint="#color/colorSecondaryText" />
change in SwitchButtonStyle it gives you some default value we are happy if you share whole file
you can see that default drawables (thumb and track) from a theme have this paddings
so the way is try to use your custom drawables (but this may affect their appearance)
app:track="#drawable/track"
android:thumb="#drawable/thumb"
I am trying to place two image buttons and some text on a single line. Here is the XML for the layout:
<?xml version="1.0" encoding="utf-8"?>
<mycompany xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="28dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/sectionDelete"
android:layout_width="35dp"
android:layout_height="28dp"
android:layout_alignParentLeft="true"
android:src="#drawable/button_delete" />
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/sectionDelete"
android:text="test"
android:textAllCaps="true"
android:textColor="#color/navigation_bar"
android:textSize="16sp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/sectionAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/button_add" />
</RelativeLayout>
<View
android:id="#+id/line"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/darker_gray" />
</LinearLayout>
</mycompany>
The selector XML for each of the buttons in drawable:
button_delete.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/delete_button_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/delete_button"
android:state_focused="true" />
<item android:drawable="#drawable/delete_button" />
</selector>
button_add.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/button_add_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/button_add_normal"
android:state_focused="true" />
<item android:drawable="#drawable/button_add_normal" />
</selector>
In the builder all looks well:
But in the application the gray background is lost and the edges of the image (which are transparent) are shown, but only for the first image:
Strangely, the first image button is not recognizing the transparent background of the image. Additionally I needed to mess with the width and height of the RelativeLayout and the first ImageButton to even get it close to the right size. With the 2nd I did not have to do anything. There is nothing special with the first image.
Here are the images from the directory:
One last issue - How do you make the text wrap before the 2nd image if it is too long for the space? Right now it writes under the 2nd image before wrapping:
Here are all the delete images. Seem to have transparent backgrounds, but I am far from a Gimp expert. Also not sure if StackOverflow keeps the original..
Update
I have verified the images are transparent. The image still has the white background. I have also updated the XML to look like this:
<?xml version="1.0" encoding="utf-8"?>
<mycompany xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/sectionDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/button_delete" />
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/sectionDelete"
android:layout_toEndOf="#+id/sectionDelete"
android:layout_toLeftOf="#+id/sectionAdd"
android:text="test"
android:textAllCaps="true"
android:textColor="#color/navigation_bar"
android:textSize="16sp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/sectionAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/button_add" />
</RelativeLayout>
<View
android:id="#+id/line"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/darker_gray" />
</LinearLayout>
</mycompany>
You should use:
<ImageButton
android:id="#+id/sectionDelete"
android:layout_width="35dp"
android:layout_height="28dp"
android:layout_alignParentLeft="true"
android:src="#drawable/button_delete"
android:background="#android:color/transparent"/>
Use "#null" like background on ImageButton:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/bkash"
android:id="#+id/bid1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#null" />
You haven't included the actual PNG file you are using as an icon for your delete button (screenshot from Windows's Explorer showing this file on your disk isn't quite enough), but I am almost sure that this file lacks an alpha channel. Instead, there is a white color on every pixel you'd like to be set with zero alpha channel value.
Opening your graphic in some image editor and changing these white pixels to transparent will solve your problem, but as for the reason why your layout "looks different" in builder than on your device, it's because there is a default theme applied by the system to every app, you can read more about it here: https://developer.android.com/guide/topics/ui/look-and-feel/themes.html
This default, OS and device specific set of values determines things that aren't determined by app's authors.
In the case of your device, its OS determined app's background color to be gray, which wasn't the case with your builder. Your builder chose the background to be white. Your delete button's graphic never was transparent, but on the white background of your builder it looked like it was.
To make it look like on builder, you need to specifically apply the background by yourself to the root of your view. In this case, it's a LinearLayout which should look like this:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
1) #DimDim had the right solution, if it didn't work, the delete button may have white background in the image, cross check with a png viewer.
2) To prevent overflow of text, try this
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/sectionDelete"
android:layout_toLeftOf="#+id/sectionAdd"
android:text="test"
android:textAllCaps="true"
android:textColor="#color/navigation_bar"
android:textSize="16sp"
android:textStyle="bold" />
And put the sectionAdd Image button above this textview in the XML as this textview needs reference to the sectionAdd.
I am using AutoCompleteTextView in my layout. But it's colorControlNormal and Activate is not Working as I expected.
My Color value is #0072BA.
Below is figure for Different Device.
1.) Android Kitkat
2.) Android LolliPop
3.) Android Marshmallow
Xml code that i used is below
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/md_black_1000"
android:layout_marginTop="5dp"
android:textSize="15sp"
android:text="Medical Store Name"
android:textColorHint="#999999"
android:layout_below="#+id/search_drug_store"
android:id="#+id/autoCompleteTextView_storename"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"/>
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="12sp"
android:textColor="#999999"
android:layout_below="#+id/autoCompleteTextView_storename"
android:layout_marginLeft="25dp"
android:inputType="textNoSuggestions"
android:layout_marginRight="10dp"/>
I am not giving any style to AutoCompleteTextView then Why it's Happening ?
What I Have Try :
If i give this Style
Reference Material Design link :
http://www.materialdoc.com/autocomplete-view/
and give this style
<style name="Autocomplete" parent="Widget.AppCompat.Light.AutoCompleteTextView">
<item name="android:background">#color/green500</item>
<item name="colorControlNormal">#color/amber500</item>
<item name="colorControlActivated">#color/cyan500</item>
</style>
But in Lollipop nothing has Change.
Is this bug in lollipop version or i am doing something wrong ?
actually this is not solution to this problem but you can use this for unique design all over device.
i have implemented for edittext like this in xml,set background null for edittext and add horizontal line below edittext.
<EditText
android:id="#+id/newPasswordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:background="#null"
android:textColor="#color/color_black"
android:inputType="textPassword"
android:layout_marginBottom="10dp"
android:hint="Enter New Password"
android:layout_marginTop="10dp"
android:textSize="14sp"
android:layout_below="#+id/titleTextView" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="2dp"
android:orientation="horizontal"
android:layout_marginBottom="7dp"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_below="#+id/newPasswordEditText"
android:background="#color/color_standard_green" />
There is no bug in lollipop version you just not override the style of theme with your style,use in this way https://stackoverflow.com/a/26631227/4745569
I'm working on this app and I have implemented a photo slider through ViewPager. There is an imported circle page slider indicator, a project on github. It looks like this: (Sorry for the blured text, I'm not able to share the content until release. The app will be free)
My problem is that thin blue line on the top of the screen. Blue color comes from the background and it is set in the root layout of the activity. No matter what I do to the any of the layouts (changing margins or padding to negative values) this line remains there.
So I figured that it has to do with the chosen theme for the screen. Theme is set to a custom theme which has Theme.NoTitleBar as it's parent. The code is below:
This is the style file. Taken from http://viewpagerindicator.com/ by Jake Wharton.
<style name="Theme.PageIndicatorDefaults" parent="android:Theme.NoTitleBar">
<!--<item name="vpiIconPageIndicatorStyle">#style/Widget.IconPageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>-->
<item name="vpiCirclePageIndicatorStyle">#style/Widget.CirclePageIndicator</item>
</style>
This is my activity layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/accountRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradientbg"
android:orientation="vertical"
android:gravity="bottom">
<RelativeLayout
android:id="#+id/titleBar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="visible"
>
<android.support.v4.view.ViewPager
android:id="#+id/viewPagerSlider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
/>
<io.colomb.android.colombio.customviews.CirclePageIndicator
android:id="#+id/slideIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_centerHorizontal="true"
android:layout_alignBottom="#id/viewPagerSlider"
android:layout_marginBottom="20dp"
android:paddingRight="5dp"
android:paddingLeft="5dp"
/>
</RelativeLayout>
<ImageView
android:id="#+id/ivSoftboardLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/logosoftboard"
android:layout_gravity="center_horizontal"
android:contentDescription="#string/app_name"
android:layout_marginTop="10dp"
android:visibility="gone"
android:layout_marginBottom="15dp"
/>
<LinearLayout
android:id="#+id/InputFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.001"
android:layout_marginTop="-15dp"
>
</LinearLayout>
Any thoughts are appreciated.
OK solved. The thing that was bothering the adapter was the line gravity="bottom"in the root element. Also the pictures needed to be cropped more