Android - Create a settings object similar to volume control - android

As the title says, I was wondering if there is a way to add a way to create input in my Android application, by providing the user with a bar similar to the one used by Android system for adjusting the sound volume. A specific variable would change its value, according to the position of a "button" on the bar (sorry for my English). Any advice on that?

A SeekBar is what you are looking for.
Here is the design spec: https://www.google.com/design/spec/components/sliders.html#
Here is the reference page: http://developer.android.com/reference/android/widget/SeekBar.html
If you want to set the value of the position of the SeekBar, simply do:
seekBar.setProgress(position);
where position is where you want the SeekBar to be.
Getting the position of the SeekBar is a bit more involved. Firstly you must set a setOnSeekBarChangeListener and grab the SeekBar value from within the onProgressChanged method. This is a StackOverflow question that answers this well: get android seekbar value and display it on screen

Related

Can't change default SeekBar TalkBack from Custom View

Currently, when the SeekBar is selected it says "%d percent, <content description>, Seek Control" and then "Use volume keys to adjust...", which is the default TalkBack for this SeekBar, but in my case, this is useless information, since the SeekBar moves in steps, for example, it can slide to option A, or option B or option C.
What I want is when the SeekBar is selected, TalkBar should read the content description only, or even better, just remove the "%d percent".
I'm trying to modify the default TalkBack in a custom SeekBar Inheriting from androidx.appcompat.widget.AppCompatSeekBar but nothing that I've tried worked.
I've tried:
reading the accessibility documentation for custom views but changing the event text did nothing: Make custom views more accessible.
I tried to change the event.text.add("custom text") in all possible API methods. Also tried to use event.clear() before adding new text and to change the event.beforeText. Nothing worked
this solution, but when I select the SeekBar it reads nothing. I'm guessing is because we are ignoring the TYPE_VIEW_ACCESSIBILITY_FOCUSED event: https://stackoverflow.com/a/64703579/10173087.
This was a close one but didn't work because when the SeekBar is selected I need it to read something.
this solution, but I don't think there is an action to modify the SeekBar label, as we have here on the button: https://stackoverflow.com/a/41496367
Might not be 100% relevant because this is the solution for a compose component, but you can remove the percent readout by changing the stateDescription
modifier = Modifier
.semantics {
stateDescription = [your state]
}

How to create a field whose text changes in android

I am just starting with android. This is what i want to make:
Now when you click on From, a new screen would open where you can select places and once you select you will get back to this screen where instead of "Bangalore" it would be the place you selected.
What kind of a field is this ? Text field ?
Also if i want to add any effect like when you click on it its color changes, how would i go about it ? Any tutorials or documentation i can check out for this.
Yes, you will probably want to use TextView.
You can change the text it displays by using SetText(), and you can change the text color by using SetTextColor().
You need a TextView to display text, but if you want to display an image, text and be able to interact with that, then Button or ImageButton is what you need.
Your question is too broad, so I encourage you to start doing some tutorials. To implement all that stuff you'll need to learn about layouts and activities, dialogs, listviews, ... Basic Android, but it needs a minimum of experience.

How to identify an imageview drawable?

There's an ImageView in my app with a drawable that can be changed by the user and a black TextView over it. If the user changes this image to one with a black background, he won't be able to see the text.
How can I identify if the image resource is R.drawable.imageA so I can set the text a different color?
I thought about setting a tag for the ImageView, but then I would have to set it for each option, when there's only two options I care about.
I tried:
if (imageview.getDrawable.equals(R.drawable.imageA)) {
textView.setText(Color.WHITE);
}
Also tried with getResource, but neither worked.
Aside from WebnetMobile.com's answer, you could just have a variable related to which image is currently displayed.
IE. When it starts up:
boolean isImageA = true;
And then change that to false when the event to change the background is triggered. All you have to do then is check whether it's true or false.
You can't. You need to store it yourself on side and use for your comparisons, or extend ImageView and embed that functionality inside (i.e. by adding getDrawableId())
Are you going to provide the user with a Dialog box / selection mechanism where the user gets to pick the image ?
If the answer to the above is Yes, then this is the place where you should be able to capture this decision within your application, and then modify the color of the TextView .
If the answer to 1 is no, then how does the user change the Image within your application ?
In your case, you may also be able to use reflection to achieve your goal. For example, take a look at this thread -> Android, getting resource ID from string?
Added later:
For a truly generalized solution, you may want to inspect the ImageView itself, to determine the optimal color to display. This has been demonstrated in this thread:
Automatically change text color to assure readability

How to handle a decibel meter type component/widget?

I'd like to be able to have some sort of volume panel looking something like :
|||||||||||||||||||||
Where the lines highlight according to how loud/quiet the sound is according to decibels. Is there a built in Android component to handle this, or does anyone have any ideas as to how I could handle this?
My approach would be to use a Rating Bar and override the android:numStars value to be the number of bars you want. Then, create a drawable that will replace the star images with bars. Really hope this helps.
Best of luck.

Am I thinking of a ProgressBar or something else? Android

I am new to Android/Java/Programming...
I am not sure if I am researching the correct term, but I am looking to have a horizontal bar on my application with no animation. The bar will show a static number from x to y based on a selected button from the user.
Can a ProgressBar be used as a standalone graphic like a bar graph? What is the correct term for me to research?
Edited to add…
Can I remove the user functionality from being able to adjust the seekbar?
The progress bar is used to show progress of some operation and it used the concept of threading.
In your case I think you are talking about seekbar ,.. the value of seekbar can be changed in the application through appropriate controls..e.g onbuttonpress or editing value in textbox
hi what you are looking for is actually a seek bar...
Go through this for a sample
I think you are looking for SeekBar.
A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys.
For more details go through these links: link1 & link2
Hope this will solve your issue.

Categories

Resources