0

I have this code but it is all cap is there any solution ? I need first word as cap and the rest as lower

 @Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
    inflater.inflate(R.menu.about_us_menu,menu);
    MenuItem menuItem = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) menuItem.getActionView();
    searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
    searchView.setQueryHint("Search here...");

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String s) {
            processsearch(s);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            processsearch(s);
            return false;
        }
    });
    super.onCreateOptionsMenu(menu, inflater);
}
Joe
  • 25
  • 1
  • 6

4 Answers4

0

you can use this code from this link:

String name = "mohsen Naderzadeh";
String s1 = name.substring(0, 1).toUpperCase();
String nameCapitalized = s1 + name.substring(1);
System.out.println(nameCapitalized);
0

the following method will check the string and if its length is greater then 0 and the first character is an alphabetic then it will capitalize it:

String search = "sometext to search";
if(search.length() > 0 && Character.isAlphabetic(search.charAt(0))) {
    search = String.valueOf(Character.toUpperCase(search.charAt(0))) 
            + (search.length() > 1 ? search.substring(1) : "");
}
Mustafa Poya
  • 1,814
  • 1
  • 11
  • 20
0

Use below input type.

searchView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
ShreeshaDas
  • 2,032
  • 2
  • 15
  • 34
0

Inside onQueryTextChange use this:

    if(s.length()==1){
         s=s.toUpperCase();
         //set s as search text
    }
Unknown2433
  • 163
  • 2
  • 11