How to set progressDrawable to a RatingBar dynamically using LayerDrawable - android

I want to set progressDrawable to a RatingBar. I was able to do this using (layer-list) via xml. Here is my layout ....
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stepSize="0.5"
android:rating="3.0"
android:id="#+id/ratingbar_default"
android:progressDrawable="#drawable/star_rating_bar_full"
/>
Here is my star_rating_bar_full
where star2 and star1 are images for specifying rated star and unrated star.
The output was fine and the RatingBar looked great. I was able to rate also. Now i want to apply the same logic dynamically using LayerDrawable
I have tried to use the following answer Dynamic RatingBar. I was able to display the RatingBar but the edges were cut at the right side of Rating Bar. The functionality was working fine but this is the only problem i am facing.
Any ideas ??? Why the rating bar edges has been cut of at right side.

Related

How to change Floating Action button shadow colour

I want to change Floating Action button shadow colour from black/grey to colorprimary/custom color of shadow ** shadow example like below image with **center blue FAB button with light blue shadow not grey shadow. But we can change the FAB button background color. But as you can see in image there is blue shadow of FAB button.I want to achive that thing.
try this :: app:backgroundTint="#color/colorAccentGrey"
where colorAccentGrey = YourColor
and put xmlns:app="http://schemas.android.com/apk/res-auto" at the beginning of the XML if you forggt,
and for Remove shadow :: app:elevation="0dp"
Hope this will help you.. :)
I think you have 2 options:
as #Uttam said, change the elevation of the FAB widget
to make a custom design and embed it as an image in your layout as shown here http://androidgifts.com/android-material-design-floating-action-button-tutorial/
None of the answer worked for me. So i worked this. anyhow it will give shadow like effect that enough for me
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_black"
app:elevation="0dp" // disable outside shawdow
app:borderWidth="30dp" // make borderwidth to 25dp or height of fab
app:backgroundTint="#00E5FF" // now you will see only this color with shawdow
android:backgroundTint="#00E5FF" // since border is 30dp u ll not see this color and if you want to check reduce border width to 25dp then ull see this color in center as a small dot.
/>
A simple solution is to remove the stroke(border-width), the default value is 0.5dp change it to 0dp, that is
app:borderWidth="0dp"
Refer Regular and mini FAB key properties in Material Design documentation!
Link - https://material.io/components/buttons-floating-action-button/android

Change Android EditText background color

I am developing an Android app. There's this issue with the EditTexts, because in some devices the "background" is white (which is the way I want it), but on others is transparent, and makes the app less professional. Here's an image with the "white background":
On other devices the edit texts that say "Yo" and "Casa" are transparent, so the words mix with the map and its pretty awful. I have tried changing the background color in the android layout xml. The closest one was I believe #drawable/white, but slightly changes the position and size of the edit text, making them look like they're one and its even worst.
Here is an example:
Is there a nice way to approach this problem? I read somewhere that an option was to add a white background image to the edit texts, but seemed like a lot of trouble.
UPDATE
I tried adding a background image, but its the same as changing the background color to any color using the android:background, the edit texts get like smaller or something. I added a blue "delimiter" to the image and this is the result:
But I want them like in the first picture, not so close one to another.
This would be the code of the edittext layout XML, the other one looks very similar. Only by adding the android:background tag changes from picture 1, to picture 3
SOLUTION
To solve this what I did was set a background image and set its height in dp as follows:
<EditText
android:id="#+id/markerTitle"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/buttonModifymarker"
android:ems="10"
android:inputType="textPersonName"
android:text="Título"
android:background="#drawable/editwhite"
>
Why don't you try setting the background of EditText programmatically?
yourEditText.setBackgroundColor(Color.WHITE);
or...
yourEditText.setBackgroundColor(Color.parseColor("#ffffff"));
simply you can add android:background="#drawable/white" attribute to your element in layout xml. you can use a lot of color resource between the double quotes (like from android color resources).
put the following image which has a solid white background in the drawable folder (it may dont appear because it's white and this page's background is white also) right click under this paragraph and select "Save Image as".
and refer to it in your layout and you will get a result like the following image
if the issue continue after trying this, please show me your layout code or email me at : mohamed_hamed4158#yahoo.com , thanks for voting my answer :)

Android :Button drawable Top

I want to create metro UI, so I did like in the picture But the problem is the position of the icons, they are in the top of the button, and I don't think it's aesthetic interface. I inserted the icons in the drawable Top in the button. Well how can make the a little bit in the middle.
You have to set the android:paddingTop and android:paddingBottom eqaully. Just don't copy and paste 10dp as the value of the padding. Value depends on the size of your button. Refer to below:
<Button
android:id="#+id/find_teacher"
style="#style/page_button"
android:drawableTop="#drawable/ic_search_light"
android:text="#string/find_teacher"
android:paddingTop="10dp"
android:paddingBottom="10dp"/>
This is the output:
I can remember 2 options:
top padding
gravity
You might wan't to check the layout documentation

How to make TextView's background to be transparent?

There is a tablelayout having four tablerows, the first tablerow contains a TextView :
As you can see the background of the TextView having the text "Vidy" is seen ! So how to make it transparent ? I tried to add android:alpha="0" to the attribute of the TextView but at runtime the text is not seen !
You can try:
android:background="#null"
Or:
android:background="#android:color/transparent"
Check also: Android Transparent TextView?
If you really need transparency, #Nermeen's answer is great, you can also get it done programmatically like:
myTextView.setBackgroundColor(Color.TRANSPARENT);
but as long as you have solid background color below, it's better due to performance to make your TextView's background color the same as the layout below (with alpha, app needs to redraw more regions). It won't really matter for such a simple layout, but it's worth remembering when you have many of them using transparency.

Android RatingBar - quarter star step size

I'm working with a default rating bar and require a stepSize of .25 - according to the docs, this should be a simple matter of setting the xml attribute android:stepSize to 0.25.
Currently, that is in place, with the total xml as:
<RatingBar
android:id="#+id/ratingbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/RatingBarBig"
android:layout_below="#+id/score"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:paddingBottom="5dp"
android:layout_centerVertical="true"
android:isIndicator="true"
android:stepSize="0.25"
android:numStars="5"
android:rating="0"/>
I'm filling the ratingbar programmatically with a float of 3.25 using the following code:
float rating = 3.25f;
RatingBar mRating = (RatingBar) findViewById(R.id.ratingbar);
mRating.setRating(rating);
so, the problem is that the rating bar itself is being filled to show 3.5 instead of 3.25. I've even set Log.d notices on both the rating float and the output of mRating.getRating
Anybody have any ideas?
Ah - so after 2 days of trying to figure this out, I finally ask SO, and what happens? I figured it out ten minutes later...
The issue was in my drawable.
What I forgot to mention, is that I'm using a second RatingBar, overlayed on top of the first one (with just empty transparent stars), as I'm using a colour filter on the primary one in order to change the colour of the stars based on the rating (red, yellow, green).
What was happening is that the drawables I was using for the primary RatingBar needed to use the exact same ones as the overlay - and not the ones I was using that were left over from my previous theme...
So, it all comes down to the images used, not the code. I'll accept this as the right answer once I'm allowed to.
Try setting the step size programmatically:
mRating.setStepSize((float) 0.25);
call this before mRating.setRating(rating);
See if this works

Categories

Resources