How to get accessibility focused current item Android - android

I am working with android accessibility. For my requirement i have to get accessibility currently focussed item. i.e. Currently highlighted item in screen.
Something like
if(myButton.isHighlighted)
{
}
I tried all below but nothing workout for me...
if(mybutton.isFocused())
if(mybutton.isSelected())
if(mybutton.isAccessibilityFocused())
if(mybutton.isEnabled())
if(mybutton.isActivated())
if(mybutton.isFocusable())
if(mybutton.isPressed())

You can call isAccessibilityFocused

try these attributes on Button in the layout
android:focusable="true"
android:focusableInTouchMode="true"
and must call inside java file:
mybutton.requestFocus();
After this check, if button is focused with accessibility.

Related

I want to create a view above the soft keyboard

I am developing a Android Soft Keyboard. I want to create a layout above the Soft Keyboard. Whenever keyboard show on the screen the layout must visible.
You can easily understand my idea by seeing this image.
As mentioned by Jawad Ahmend in the comments, it's possible to attach the layout to the top of the keyboard by attaching it to the parent bottom using ConstraintLayout. You'd essentially need to do the following steps:
Set the windowSoftInputMode as adjustResize for your activity in the manifest.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize"
android:theme="#style/AppTheme.NoActionBar">
Set your layout visibility to gone and add a layout constraint attaching it's bottom to the bottom of the parent.
<LinearLayout android:id="#+id/layout_B"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
Next, you need to monitor the soft keyboard state. To keep this short, let's just use the KeyboardVisibilityEvent library. Add the following line to your app's build.gradle and sync it.
implementation 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.3.0'
Add a keyboard listener in your activity to set your layout_B to become visible when the keyboard opens and you're done.
KeyboardVisibilityEvent.setEventListener(this) { keyboardIsOpen ->
layout_B.visibility = if (keyboardIsOpen) {
View.VISIBLE
} else {
View.GONE
}
}
If you're writing the keyboard, its easy. Just override onCreateInputView to return the view you want. This can easily be a linear layout with your extra views and the keyboard itself in it.
The bigger problem I see is you have an EditText in there. That's not going to work. Tapping on the EditText is going to break the InputConnection to the actual app and cause... unknown weird behavior. I'm not even sure if the behavior will be defined across different OS versions. It may cause the keyboard to immediately hide. It may cause the keyboard to just stop working at all. The OS isn't meant for that.

How to disable the Android ripple effect for quick taps?

In certain apps like Google Play, quickly tapping / clicking views do not show a ripple effect.
If you long press an element the ripple is shown.
How is this effect achieved?
Thanks
Try set properties view in layout:
android:clickable="false"
AFAIK You need to set other selector on that view. Ripple effect uses sectors which have "ripple" node in the xml. Just use old type of selectors for Android <21 and it should work tag you want.
I think what you are looking for is app:rippleColor attribute (if Material design library is used). So if you want to disable the ripple effect on a Button for example, set its ripple color to transparent:
<com.google.android.material.button.MaterialButton
...
app:rippleColor="#android:color/transparent" />
I've already answered anther similar question.

Change image Floating Action Button Android

I used this library https://github.com/futuresimple/android-floating-action-button. How can I change the image of the main button? I want to change the button image right after selecting one of the smaller buttons.
From https://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html
As this class descends from ImageView, you can control the icon which
is displayed via setImageDrawable(Drawable).
Or you can use setImageResource():
fab.setImageResource(R.drawable.ic_shopping_cart_white);
you can use this in your .XML :
android:src="#drawable/icon" // change backgroung icon
app:backgroundTint="#color/icons" // change background color
use this in code:
mFloatingActionButton.setImageResource(R.drawable/icon2);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab_btn);
// State 1 -on
fab.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.fab_on));
// State 2 - off
fab.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.fab_off));
In Kotlin, this will be:
#RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private fun pauseTimer() {
floatingActionButton.setImageDrawable(getDrawable(R.drawable.ic_baseline_play_arrow))
I faced same issue recently, I tried with following option
fab:fab_icon="#drawable/icon"
and
android:src="#drawable/icon" // change backgroung icon
even tried programmatically
fab_menu_btn.setImageResource();
Nothing worked.
Solution: In app's build.gradle file replace
compile 'com.getbase:floatingactionbutton:1.10.0'
to
compile 'com.github.toanvc:floatingactionmenu:0.8.9'
In .xml file Use:
<toan.android.floatingactionmenu.FloatingActionsMenu
</toan.android.floatingactionmenu.FloatingActionsMenu>
In activity File:
floatingActionsMenu.setIcon(getResources().getDrawable(R.mipmap.icon));
In the Material design version:
build.gradle (app)
defaultConfig {
vectorDrawables.useSupportLibrary = true // For srcCompat
}
dependencies {
implementation 'com.google.android.material:material:<version>'
}
XML (for set icon)
app:srcCompat="#drawable/ic_google"
app:tint="#color/colorGoogle"
More documentation: https://material.io/develop/android/components/floating-action-button/
I had the same problem and I managed to create my own solution. Maybe some else founds it also useful. I have posted the complete answer to another question (How to set an icon to getbase FloatingActionsMenu) but this part posted here is relevant to the question in dynamically changing the main menu button picture/image when one of the sub buttons is chosen. In this case, you need o combine the answer from the "linked question" and the answer below.
In order to change the icon on the menu button when you choose a floatingActionButton it can be implemented like this:
Create menu button in xml file, create floating button(s) on .java file (programmatically) set menu button (color button, color pressed button and image). Then simply add all buttons to the menu button. You can also deactivate the animation of the menu button by simply commenting out the code in FloatingActionsMenu class.
Then every time that you create a button, sample:
final FloatingActionButton actionA = new FloatingActionButton(getBaseContext());
actionA.setTitle("Familie");
actionA.setIcon(R.drawable.world_map);
actionA.setSize(FloatingActionButton.SIZE_MINI);
actionA.setColorNormalResId(R.color.red);
actionA.setColorPressedResId(R.color.black_semi_transparent);
actionA.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
menuMultipleActions.setMenuButton(R.drawable.icon, R.color.red_transparent, R.color.black_semi_transparent);
Toast.makeText(MainMapView.this, "Action Description", Toast.LENGTH_SHORT).show();
((FloatingActionsMenu) findViewById(R.id.multiple_actions)).collapse();
return;
}
});
See the answer posted on the link on how to configure the classes and define the menu button and floating button(s).
So the important part to notice here is:
menuMultipleActions.setMenuButton(R.drawable.icon, R.color.red_transparent, R.color.black_semi_transparent);
This method you need to add in the FloatingActionsMenu class. Simply you call the method after on every floatingActionButton you want to update the image.
More information you can find on the link that I have posted. So when you click one of the floatingActionButton(s).
For the moment the color on the menu button is not updating correctly but I am working on it if I find a solution I will update the answer here as well. Hope this helps, happy coding.
Unfortunately with this library you can't change the icon from the menu (see issues from this library from more info)
That is why I dropped this library to use a way more flexible one! It is originally a fork but it is now more advanced.
Here is the link
Add the property
fab:fab_icon="#drawable/fab_expand"
in the xml where you initialized the floating action menu.

Not able to enter values in EditText

I'm a newbie in Android development. Recently I have been facing a problem in the EditTexts(eventhough I havent changed any attributes of EditText) used in my app which I'm currently running in Emulator.
On clicking the EditText it receives focus, but on typing something the focus changes to some other view. But I'm able to enter values if I navigate to EditText using Tab button of the keyboard. This happens to all EditTexts in my application.
Surfed net for getting a solution, but did not find one.Help...
Implementation of one of my EditText:
<EditText
android:id="#+id/edittext_testname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/hintEditText1"/>
Thanks in advance.
Ever tried your app on a physical device?
However, I cannot see anything wrong with your EditText xml. Perhaps there is some java code in your activity catching any events related to that EditText? Or maybe to the other view element you mentioned getting the focus?
I had a similar issue but with a custom style I had defined for my EditText. How I fixed it?
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
So try applying the "android:focusable" and "android:focusableInTouchMode" properties and see if it makes any difference. They should be applied to the EditText by default but give it a go.
(I would have posted this as a comment but I need more rep)

Change android softkeyboard sample designs, button and background images

I'm building a custom keyboard by modifying the android softkeyboard sample from the SDK. I want to change the images of the buttons and the backgrounds but I can't figure out where those values are stored. Where are they stored or how can i change the image or simply color?
in onClick method you need to change the Button's image, this way..
public void onClick(View v) {
if(v==buttonName){
buttonName.setBackgroundResource(R.drawable.imageName);
}
}
The keyboard background color can be changed in input.xml using android:background
You need to edit the file res/xml/qwerty.xml.
You can check the documentation for Keyboard and the Keys. The last one defines what is shown on the keys (does not look like you can change the background though).
You need to edit the file
res/layout/input.xml
A sample input.xml could look like this.
<com.example.keyboard.LatinKeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/keyboardbackground"
android:keyBackground="#drawable/samplekeybackground"
android:keyPreviewLayout="#layout/input_key_preview"
android:keyTextcolor="#android:color/black"/>
there are few more attributes that can be found in the KeyboardView documentation.

Categories

Resources