So basically I am implementing talk back feature for my android app.
There is Edit Text View for user to write there phone number and then there is a button for sign up. If user hasn't given any phone number the Sign Up Button is disabled.
When the Button is disabled it the talk back should say "Sign Up Button Disabled, Please enter a valid mobile number." But since there is default string which talk back is saying at the end i.e : Button Disabled.
How to remove the default string being said for a particular view.
verifyButton.disable()
verifyButton.contentDescription = requireContext().getString(R.string.sign_up_button_disabled_phone_number_accessibility_label)
You can achieve this by attaching an AccessibilityDelegate to the view:
ViewCompat.setAccessibilityDelegate(submitButton, object: AccessibilityDelegateCompat() {
override fun onInitializeAccessibilityNodeInfo(
host: View,
info: AccessibilityNodeInfoCompat
) {
super.onInitializeAccessibilityNodeInfo(host, info)
if (!submitButton.isEnabled)
info.stateDescription = getString(R.string.accessibility_button_not_enabled_reason) //"Please enter a phone number"
}
})
This will update every time the state of the view changes so you won't need to manually do it on validation.
This will announce:
"Please enter a phone number, [Button Text], Button, Disabled"
So the user will still be aware of the button and it's intention and additionally why it's disabled!
Related
In Android Studio I have a Kotlin project with a button that sends an SMS message. When the Send SMS permission for the app is denied, the button is disabled. When a user clicks the disabled button, I would like to display a toast message to the user:
Toast.makeText(this, R.string.smsDisabled, Toast.LENGTH_LONG).show()
However, after much research I haven't been able to make this disabled button clickable. I have tried things like smsButton.isClickable = true on the button, but it still doesn't work. If it is possible to style the button to simply look like it is disabled, that would work too. My button style is currently set to #style/Widget.MaterialComponents.Button and I haven't had any success in changing the button colors. I have tried applying a background, backgroundTint, custom theme, and creating a custom background like in this question.
I am new to Android Studio so I have limited knowledge and experience. Is there a way to achieve this functionality?
Here is what you can do:
if (isPermissions) {
//keep the button as it is or do what you have to when button is enabled
} else {
//change the button color and maybe icon two
button.setBackgroundColor(ContextCompat.getColor(applicationContext, R.color.grey))
button.setOnClickListner {
//show toast
Toast.makeText(this, R.string.smsDisabled, Toast.LENGTH_LONG).show()
}
}
isClickable only makes it clickable once again if the click is disabled with the same attribute.
Try:
button.isEnabled = true
I want to have the user use fingerprint authentication to allow them to perform an action within my app. I have already performed the necessary check, does the hardware exist, is a fingerprint registered etc when they say they would like to use fingerprint auth.
An alertdialog currently opens when it is time for the user to authenticate with their fingerprint. I'd like to know if it is actually possible to catch the fingerprint through an alertdialog as and alertdialog afaik only has positive and negative button input options.
If it is not possible to do this through an alertdialog, a point in the right direction would be much appreciated.
EDIT: Just to be clear, I don't mean using the screen as a fingerprint sensor.
You can use this FingerprintDialog library. Then it goes simply like this :
FingerprintDialog.initialize(this)
.title(R.string.title)
.message(R.string.message)
.callback(new FingerprintCallback({
#Override
public void onAuthenticationSuccess() {
// Fingerprint recognized
}
#Override
public void onAuthenticationCancel() {
// User pressed cancel button
}
}))
.show();
Otherwise, you just have to create a custom xml layout, get the view using a LayoutInflater and call setView(view) on the dialog. Google it.
This currently isn't possible. Or if it is, I really doubt it. Most touch screen phones use a capacitive touch. Which means, since our fingers conduct electricity, we disturb the electric fields infront of the phone's screen. While it does support multitouch, I really doubt it's so precise that it detects the ridges on our fingers.
You would need more of a heat sensitive touch screen. Which I don't think they use in most new generation touch screens.
So you could use this API https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.html but only in device that contains fingerprint scan and definitely not through the screen of you device.
I'm developing an Android TV application which is using Leanback library. There is a login form with email, password and a login button. I'd like to enable the login button only when the email and password are valid.
Here is my code:
mLoginButtonAction = new GuidedAction.Builder(this.getActivity())
.id(id)
.title(title)
.description(desc)
.build();
actions.add(action);
I disable it at first:
mLoginButtonAction.setEnabled(false);
And then enable it when it's valid:
mLoginButtonAction.setEnabled(valid);
The button is then enabled and I'm able to click it. But the color of the button is still the same color as in disable mode. Any idea? Thanks.
Modification to actions do not trigger notifications to the GuidedStepFragment and must be done so manually.
To notify an action change you first need the items index.
int idx = findActionPositionById(actionId);
Get and modify your action
GuidedAction someAction = getActions().get(idx);
someAction.setEnabled(valid);
Next notify the fragment of the update
notifyActionChanged(idx);
Helo,
Is there a possibility to click on button and show a popupover and inside it there is two buttons. When i click on each of them , i have an alert.
If there isn't a possibility with a popupover is there a possibilty of any other popup window?
My Android application is developped in phonegap
Thanks a lot
Take a look at the cordova dialogue api.
https://github.com/apache/cordova-plugin-dialogs/blob/master/doc/index.md
I think you are looking for the navigator.notification.confirm feature.
Using this feature you can display a popup with multiple options for the user to tap on.
The index of the button the user taps on is returned to the confirmCallback, so you can handle the user input.
navigator.notification.confirm(message, onConfirm, [button1], [button2]);
function onConfirm(buttonIndex) {
alert('You selected button ' + buttonIndex);
}
perform operations based on buttonIndex.
I am stuck in a scenario. I have a login Form. I want to show it as disabled for some users. I can get that users but I dont know how to remove the focus from the window.
//to check whether the current user is administrator or not
public void checkAdministrator(){
String owner = ParseValues.parsedGroupList.get(indexofGroup).getGroup_owner();
String currentUser = CCMStaticVariable.loginUserId+"#abc.com";
if(owner.equalsIgnoreCase(currentUser)){
administrator=true;
}
else{
administrator=false;
}
}
Now -
if(!administrator){
//here I want to disable the whole Activity, I just want to show the activity in disabled state
}
First get your parent layout from your login xml and try this
parentLayout.setEnabled(false);