set the cursor to search view automatically - java

I have a button in an activity, on clicking that button, I direct the user to a search activity with a search view in the toolbar..
I'm using android.support.v7.widget.SearchView, I managed to expand it automatically using searchView.setIconifiedByDefault(false) in onCreateOptionsMenu..
I also open the keypad automatically in activity onCreate, yet I still have to click in the searchView to start typing there, I want the cursor to be set there automatically..
any help?

call setIconifiedByDefault(false) when the searchview is intialized.
Sets the default or resting state of the search field. If true, a single search icon is shown by default and expands to show the text field and other buttons when pressed. Also, if the default state is iconified, then it collapses to that state when the close button is pressed. Changes to this property will take effect immediately.
Try the below, it worked for me once.
searchView.setIconifiedByDefault(true);
searchView.setFocusable(true);
searchView.setIconified(false);
searchView.requestFocusFromTouch();
Update: If you are Using android.support.v7.widget.SearchView the behaviour is very different. clearFocus is needed if you don’t want the keyboard pop-up all the time.
Also in the searchview layout, use <requestFocus /> tag.

Related

To remove the back arrow button from Action Bar

In my Android Project, whenever I go from First Activity to Second, I get an left arrow button followed by the some text in the action bar. That left arrow only comes when I set my First Activity as the hierarchical parent of the Second Activity.
I want to remove that back button and replace it with an icon. I have read other posts for the same question, and so I have already tried the following code in my onCreate() method.
getActionBar().setDisplayHomeAsUpEnabled(false);
But after reaching to the second activity, the app gets crashed.
Please help me out.
Use getSupportActionBar() bar:
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_yourindicator);

View's contentDescription does not work correctly with TextToSpeech

I work with TextToSpeech and adding "android:contentDescription="#string/custom_button" for ImageButton in xml, reads the value from "#string/custom_button" and adds another "button" in speech.
EG:
"#string/custom_button" = "Custom Button" mapped for mentiond ImageButton, is read as "Custom Button button". There is no text in this button. Id is much different.
How to get rid ot this last "button". It refers to all views read by TextToSpeech.
From my work/research with accessibility, Android automatically adds "button' to the end of talk back for buttons. I could not find any documentation breaking now accessibility to the coding level, but from what i gather they probably add this in the case the developer forgets to indicate in the content description that the the user has clicked a button. There is nothing you can do to remove android's addition of the word button. What you can do is remove it from you custom description so that is only says "Custom". Hope this helps.

how to remove the cursor from an editView?

I have up to 4 edit views (amount changes dynamically) in a linearLayout
how can I set the cursor to appear in none of them at the beginning?
This activity ignores onConfigurationChange and i want to de-select previous user choice.
meaning in the onCreate i want to de-select all of them.
I have tried this:
findViewById(R.id.editText1).setSelected(false);
for each of them, but the cursor stayed.
I want the curser appear again when the user clicks but then disappear again onCreate (after screen rotation till another user click)
findViewById(R.id.editText1).setCursorVisible(false);
this will make the caret not visible, even if the edit text is enabled, selected and being edited
Try:
android:windowSoftInputMode="stateHidden"
in your manifest for each activity in which you do not want focus for the edit text at the start.

Keyboard doesn't show when EditText is clicked

I'm having a problem with the softkeyboard not showing when i click on a EditText.
The activity goes like this.
1. Activity starts
2. Dialog box opens with a custom keyboard
3. And then I try to click on an empty EditText field to put in data, but nothing happens. The field get focus, but keyboard doesn't show up.
I haven't done anything funky with disabling keyboard..
Anyone know whats going on?
If you're using AVD manager add a hardware property Keyboard support and set it to false.
That should disable the shown keyboard, and show the virtual one.

PreferenceActivity, how to make a Preference item that will navigate back through menus?

My overriding question is this: In Android PreferenceActivity, how can I write an OnClickListener which will have the same functionality as pressing the Android back button as I navigate through PreferenceScreen defined menus? That is to say, I would like users of my App to explicity see a menu choice "Back" which will bring them to the previous menu, or bring them out of the menu activity to their previous activity if they are at the root of this particular PreferenceActivity session.
The android developer documents tell us
Note that this XML resource contains a preference screen holding another fragment, the Prefs1FragmentInner implemented here. This allows the user to traverse down a hierarchy of preferences; pressing back will pop each fragment off the stack to return to the previous preferences.
And they are correct about that. I navigate happily through my menus by clicking on PreferenceScreen items to get to that screen, and using the Android back button to go Back up a level. But I'm not sure a casual user really understands the "Back" button, I know I didn't until I read about it in Developer docs. SO I would would like them to have an explicit Preference defined menu choice whos OnClickListener duplicates the function of the Android back button.
So I tried to put in a Preference in my menu that would go back. Having determined that a not Overriden onBackPressed in a my subclass of PreferenceActivity just referred back to Activity.onBackPressed() which merely calls finish(), I tried this OnClickListener:
private OnPreferenceClickListener clickFinishesSuccessfully = new OnPreferenceClickListener() {
#Override
public boolean onPreferenceClick(Preference preference) {
finish();
return true;
}
};
As it turns out, this did NOT do the same thing as pressing the back button! Pressing this button always took me out of the PreferenceActivity entirely, back to the Activity from which I had called my PreferenceActivity. Specifically, it did NOT navigate back through my menus no matter how deep I was when I clicked it.
I am guessing here: When I have gotten to a submenu by clicking an onscreen preference which is really a PreferenceScreen, I am no longer in my own PreferenceActivity. I must be in some other Activity?
So my functional question: what can I put in my OnClickListener of my "Back" Preference to get the same function as the Android Back button navigating through my menus?
I think the casual user should know about the back button. The button is used everywhere so it might be a problem getting used in the first day but after that it's natural. Without being used to the "back" button I can hardly imagine doing the everyday tasks.
The preference you want to add just duplicates functionality and doesn't provide a consistent way with the rest of the system. If Google was considering back being an uncommon thing for casual users would have added that option in phone's Settings which is also a PreferenceActivity.

Categories