I am trying to create a SearchView and programatically change textcolor and add filters e.g. max length.
SearchView search = findViewById(R.id.searchView1);
TextView textView = search.findViewById(R.id.search_src_text);
textView.setTextColor(Color.rgb(0, 0, 0));
textView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(15)});
This way it says Cannot resolve symbol 'search_src_text'
Then I tried:
SearchView search = findViewById(R.id.searchView1);
int id = search.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
TextView textView = search.findViewById(id);
textView.setTextColor(Color.rgb(0, 0, 0));
textView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(15)});
In this case there is No error, but only warning, that Use of getIdentifier is discouraged
My Searchview in xml:
<SearchView
android:id="@+id/searchView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="@drawable/searchfield"
/>
Is there any other way to do the same thing with SearchView without any warnings and errors?
I would suggest to replace the SearchView with
androidx.appcompat.widget.SearchViewand useHere is some information on Why to use androidX
Sample gradle update