How do I set a button as always pressed? (Android) - android

I have a bar in my app with 2 buttons side by side. One button represents the page the user is currently on and the other redirects the user to another page with the same button bar. What I want is for the button that represents the page the user is currently on to look like it is pressed (i.e. the color it would be if it is pressed). I already have it set so it can't be clicked. Is there a setting or attribute or do I HAVE to create my own selector (because I don't really understand how to implement that)?

Have never tried this but
button.setPressed(true)
should work.
Edit: You can also add
button.setClickable(false)
Edit: This does work but the order is important. Use this
btn.setClickable(false);
btn.setPressed(true);

Related

Progress Indicator inside Button on click

Is there a way to set a progress indicator inside a button (preferably using the native Material Button from Material Components - Android)? There is a video on the website showing exactly what I need, but there's nothing in the documentation about it. Here is a screenshot of the same. Wanted to use it on a login button.
I also though of using a CircularProgressDrawable, which I've used before on a chip (as a chip icon), but in case of a button, I don't think there's a way to centre an icon horizontally on a button (my button width matches parent).
If anyone knows how to do this via either of the two ways, I'd be thankful.

How to show form on button click?

I am making an android app where the user fills up a form. The client wants that out of many of the fields of the form, The user should see the compulsory fields first and then if the user wants then he/she should click on a button named as "More Fields (Optional)" and as soon as he clicks the button the button should disappear and then the user should see the other fields laid out one after the other.
The form looks like this now
I have already tried setting the visibility of the edit Text to invisible, but the problem is that even if the text fields are invisible they take up most part of the screen.
I have been scrolling through the android forums but i got no hint as to how i can achieve it.
It worked, I set the visibility to Gone and then everything happened as it was supposed to be.

How to make Image button Visible OUTSIDE the app?

I need the image button to be visible when the user opens another app, you know, i need it like the floating button that is visible to the user when the user opens any other app.
i have a switch button the controls if the image button is visible or not
Have a look at this question.
Essentially you need to use the SYSTEM_ALERT_WINDOW permission which allows you to draw over other apps, make a custom layout file which contains the button that you want to show and use the WindowManager to insert it into the view.

Android Menu Shown Where User Clicked

I wanted to achieve the same sort of functionality found in Google Now where you can tap the cards overflow icon and a menu appears next to it with options (shown here).
Does anyone know how to implement this sort thing to achieve the same style etc?
I think you can do this by placing a listview under your button, and set its visibility to invisible.
Then place an onclicklistener on your button to turn your visibility to visible.

Android Floating EditBox

I have an OptionMenu which has single option in it named "Search". When the search option is clicked, it should dynamically add a EditText at the top of Activity window like it has in WebView (browser address bar) so users could search something in my application.
After there would be EditBox, one can write inside it. I also want to have some OnTextChanged like event of that EditBox so do you think it's also available with that View?
I made it myself. I added an EditText on the screen with setting as hidden and on button click made it visible. It worked like a charm.

Categories

Resources