I have created custom style for RatingBar and when I apply my style to rating bar, it shows only one star, and in properties of RatingBar, I've define the size of the start which 5 as well, but on run time it displays only one star.
Note:I am using ActionbarActivity, in that I am displaying RatingBar, but when I use only Activity class, it displays 5 star and the theme is also applied on that.
So Please help me out from this issue.
check if you are using Vector Drawable which is causing this issue. So to work with it try to replace Vector Drawable with png image in the drawable folder and see the magic it work.
you are using Vector Drawable with layer-list so your Vector Drawable image is fit to the whole layout try to replace it with png which will solve your problem.
Try this in XML:
<RatingBar
android:id="#+id/rating_bar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rating="3.5" />
Related
This is what my floating action button is showing
rather that just showing the actual circle part of the image, it tries to fit the background of my .png file into the floating action button.
here is my xml code:
<android.support.design.widget.FloatingActionButton
android:id="#+id/addToKitchenButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_gravity="bottom|end"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:src="#drawable/fab_icon"
/>
how do I get it to look like this?
I've given my .png file a transparent background already, so I don't know what else I need to do. Please Help.
Thank You.
(Assuming you are using Android Studio) -- Rather than using your own custom .png for the FloatingActionButton's src, create a new vector asset with that icon. Right click your res/drawable folder in Android Studio, and then click to New -> Vector Asset.
The icon you are using is built in to Android Studio, although you could import your own vector asset if you were doing something more custom. The XML it generates will look like this:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
and you can change the color in fillColor. Set your FloatingActionButton to this drawable in android:src and you're good to go.
Try overriding the "design_fab_image_size" in the dimens file
<dimen name="design_fab_image_size" tools:override="true">56dp</dimen>
Also, add
app:tint="#null"
inside your FAB button XML
You dont have to provide the rounded corner image.
I am using and I my xml looks like this
<android.support.design.widget.FloatingActionButton
android:id="#+id/addFolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/plus"
app:layout_anchor="#id/mainRl"
android:background="#ff0000"
app:layout_anchorGravity="bottom|right|end"
android:onClick="onAddFolderClick"
/>
I am using #ff0000(red) as background color, you use the pink you want. It works fine for me.
For a consistent look there are two tings that you need to do. This answer assumes that you really want the look in the link provide by you which is this
First Step - The background color is nothing but your app accent color you need not provide any specific color. So first make sure you have accent color set in your app theme.
Second Step - Once you have done that you need to use the xml code below. You don't even have to create a new png if you want the look in link. You can easily download one in white color add icon from this official google material icons link . You can use this links for most of standard material icons by google.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_add_white_24dp"/>
Hope this helps. Do let me know if it changed things for you.
EDIT:: If you wish to change the icon color and background to something completely different than your default accent color then you have to use these attributes-
//for custom background
app:backgroundTint="#color/yourCustomColor"
//for custom icon color
android:tint="#color/yourCustomColor"
Hello Guys I need some help in creating Imagebutton. I created custom button on PS and then saved it in PNG format with transparent background. After that i patched my image with 9patch. Now i am using that image as a button in my layout but the image is showing colored background corners. I tried alot of things but its not removing.
Here is my XML
<ImageButton
android:id="#+id/mybutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/registerbutton"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="123dp" />
Keep the background attribute as #null like this :
android:background="#null"
If still you are getting that corner, it might be from the png file that you are using.
This is an example of what i get from #null
Probably the ouput of "9patching" operation added corners. Open the file and check if there are corners or not.
If that won' help, try switching android:src attribute with android:background attribute.
And u can make .png button online using this site
Currently I have a button that looks like this:
What I want to do is to be able to replace the text with this vector drawable but keep the blue rectangle background:
I looked into doing this but I cannot seem to get it right.
I tried the following combination:
<Button
android:id="#+id/deletebutton"
android:layout_width="0dp"
android:layout_height="50dp"
android:src="#drawable/deletebtn24dp"
android:backgroundTint="#color/primaryButtonColor"
android:layout_weight="1"/>
However that just led to a blank blue button with no drawable. What can I do so the drawable replaces the text?
Also I would like to support API levels start at 16+.
You have to use app:srcCompat="#drawable/deletebtn24dp" instead of android:src="#drawable/deletebtn24dp". Using an ImageButton might also be better than using a straight Button.
I'm developing and Android app. I have a main menu with lots of imagebuttons, each of which takes the user to a new view on click.
The problem I'm having is that surrounding each icon is a tinted rectangle that changes to a light blue colour when tapped. How do I remove this transparent square in the .xml layout file?
Many thanks in advance,
they probably have the default background from the android system. to remove that, define a transparent color
<color name="transparent">#00000000</color>
and then use it as background in your buttons
<ImageButton android:src="#drawable/button"
android:background="#color/transparent"/>
I think it will work the way you want
You could always use the framework's
android:background="#android:color/transparent"
But for what you are trying to archive this is the better solution:
android:background="#null"
I know theres now rectangle or colour, when you use your own buttons.. create, implement and use them, then you wont have the rectangle
Pretty much what the title says. I'm wanting the user to have the choice to customize the boarder of a 9 drawable I have. Is something like that possible or do I need to use a different method? Right now, I think it won't work and it will mess up the 9 patch.
Can you post a picture of your 9-patch? It might be possible to extract parts of it to another type of drawable, then layer the customizable part (drawn with user defined color) under the fixed portions using a layer-list.
[Update] Based on the pic you posted, I'd trash the layer list idea, but we can still work something out. The idea would be to remove the colored border and internal dark background from the 9-patch entirely (fill that area in with the shadow color and opacity). Then nest 3 layouts in each other. The first would use the 9-patch as a background. The second would use the user-defined color as a background. The third would use your panel color as a background. The 9-patch would provide the proper margins to position the second (user-color) layout, and then you'd just add a layout_margin attribute to the second panel to position the inner most layout a few dps in.
<LinearLayout
android:id="#+id/PanelOuter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/shadow_nine_patch">
<LinearLayout
android:id="#+id/PanelUserBorder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/custom_border_width"
android:background="#color/dialog_border_color_default">
<LinearLayout
android:id="#+id/PanelContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/custom_dialog_content_margin"
android:background="#color/dialog_inner_color">
</LinearLayout>
</LinearLayout>
</LinearLayout>
Of course, you'd be responsible for finding the PanelUserBorder view in code and calling setBackgroundColor() with the proper user-defined color.
maybe you could tint it by putting a 50% transparent view overtop the button.
after thinking about it i thought maybe you could transform the color by bitmap:
How to change Bitmap image color in android?