Rating scale continuous bar - android

I have seen that a rating scale is always a several star or any other drawable image.
I want to make a continuous bar line from 0-10 taht the user will hit on some point of it and I get the colses rate

Look into the SeekBar documentation. You can add one to your layout and allow the user to drag the slider to give their "rating". In your XML layout file, add something like this:
<SeekBar
android:id="#+id/seekbar"
android:width="match_parent"
android:height="wrap_content"
android:min="0"
android:max="10"
android:progress="5" />
(The android:progress sets the initial state of the SeekBar, which in this case is exactly in the middle. The user can then change it as desired by sliding the "thumb".)
Then, in your code, set an OnSeekBarChangeListener and react accordingly when the user changes the rating. Or just call getProgress() on the SeekBar object to get the rating once the user is done with your form.

Related

How to show slider value above the slider also when we are not sliding using material.slider in Android?

This is how I want to show the value of the slider. Please find the picture
This is currently not supported, the available options in LabelFormatter (which can be applied to sliders with slider.setLabelFormatter(...) are:
LabelFormatter.LABEL_FLOATING: Label visible during interaction only
LabelFormatter.LABEL_WITHIN_BOUNDS: Label visible during interaction only
LabelFormatter.LABEL_GONE: Label never visible
You can find the code here with the extensive javadoc explanation.
You could open a feature request for this on the Material GitHub issues page
You can set the label behaviour "visible" in the XML file. So in the slider XML code, you just need to add
app:labelBehavior="visible"
Below I am attaching a sample XML code for the same.
<com.google.android.material.slider.Slider
android:id="#+id/seek_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:valueFrom="1"
android:valueTo="100"
android:layout_gravity="center"
android:layout_margin="15dp"
app:tickColor="#0000FF"
app:labelStyle="#style/Tooltip"
app:labelBehavior="visible"
/>

Custom seek bar with thumb and progressDrawable

I try to customize seek bar like below
But problem is that
-thumb image not set with text
-thumb position can not set above seekbar.
-android:progressDrawable should not repeat as below
My Code is as below:
<SeekBar
android:id="#+id/volume_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:max="100"
android:progress="20"
android:progressDrawable="#drawable/bar"
android:secondaryProgress="0"
android:thumb="#drawable/greenarrow" />
I've tried doing this, but I ran into problems with response time the way I did it. Having to move the margins took a lot of processing power and time. It was close to 400-500ms. So I had to remove it.
However, here are the steps I took:
First, I would suggest creating a frame layout to hold both the SeekBar and a TextView. Then, depending on the percentage of the progress bar, you can set the TextViews layout property margins.
Does that make sense?
If you would like specific code, I can get that to you, but google does pretty good too. :)
Option B: Android seekbar with custom thumb having dynamic text inside it

Making a semi-transparent button such that button color should be visible and background should be visible

I have been trying to achieve this semi-transparent button, but I always failed on making that. I have referred many like this. But still no luck. I tried with android:color="#66FF0000" too, but it doesn't make it semi-transparent. Below is my code.
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:text="select"
android:onClick="selectClick"
android:color="#80000000"
/>
I want this type of rectangular button with semi transparent so that blue color of button should be visible and green color of the activity should also be visible. Can someone please suggest me? In the below picture I was unable to draw green color on the button to show what exactly I want. But I guess my above explanation is understandable.
Or if the blue color is not possible to be made visible, at least I want it to look like to give a user feel that there is a button and the green color should be visible.
Use
android:background="#80000000"
instead of
android:color="#80000000"

Android - how to exactly position an image within a normal button

Im trying to place an icon thats 16x16 pix within a normal button that I have in a layout. This button also uses another png for its background. The problem I have is not placing it within the button but placing it where I want. When I add it using the following code it places the drawable at the bottom but exactly on the edge of the image which looks terrible.
<Button
android:id="#+id/clearform"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/helpText"
android:layout_alignParentBottom="true"
android:layout_marginBottom="19dp"
android:typeface="monospace"
android:textColor="#FFFF00"
android:drawableBottom="#drawable/cross"
What I would like is to create a button in my layout that possibly has some padding from the bottom but there is no such method or xml attribute that does such a thing the way I would like. Its only left right top or bottom and when I added padding it only placed padding between the bottom of the text in the button and the top of the drawable.
So how can I accurately place an image within the button itself.
I think you can use android:padding for aligning to a greater extent & use android:paddingTop/Right/Left/Bottom to get the exact postion.It would be much easier.

Button to be focussed & in default selected condition

I am displaying a the Terms & Conditions screen of the mobile application as the first screen.
I am using a layout file to display the screen.
Within the layout file , I have two buttons , one for Accept & one for Reject
<Button android:id="#+id/acceptBtn" android:text="#string/accept"
android:background="#drawable/buttons" android:textColor="#color/white"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:id="#+id/rejecttBtn" android:text="#string/reject"
android:background="#drawable/buttons" android:textColor="#color/white"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
The requirement by default is , the Reject button should be in selected condition. Also , currently , because of the android:background="#drawable/buttons" which is an image , the buttons are not getting focussed.
Kindly provide your inputs/sample code/xml to solve the issue.
Thanks in advance.
The problem is that the focus indicator on a button is nothing more than a background image. So when you set your background with a drawable you prohibit the system to use the focused background image when the button changes its state.
A simple solution is to use ImageButtons and to set your drawable as the src attribute. Then you have a button with your image in the center. The underlying background can change to the default focus background image. If you don't want the grey area underneath your image and still want to use buttons you would have to define customs styles depending on the state of the button. Please have a look in this similar post: Remove focus border of EditText
There I already explained this scenario.

Categories

Resources