本文整理了Java中android.widget.SearchView.getContext()
方法的一些代码示例,展示了SearchView.getContext()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SearchView.getContext()
方法的具体详情如下:
包路径:android.widget.SearchView
类名称:SearchView
方法名:getContext
暂无
代码示例来源:origin: stackoverflow.com
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
// Getting SearchView from XML layout by id defined there - my_search_view in this case
SearchView searchView = (SearchView) menu.findItem(R.id.my_search_view).getActionView();
// Getting id for 'search_plate' - the id is part of generate R file,
// so we have to get id on runtime.
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
// Getting the 'search_plate' LinearLayout.
View searchPlate = searchView.findViewById(searchPlateId);
// Setting background of 'search_plate' to earlier defined drawable.
searchPlate.setBackgroundResource(R.drawable.textfield_searchview_holo_light);
return super.onCreateOptionsMenu(menu);
}
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.entity_list_actions, menu);
final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
final int textViewID = searchView.getContext().getResources().getIdentifier("android:id/search_src_text",null, null);
final AutoCompleteTextView searchTextView = (AutoCompleteTextView) searchView.findViewById(textViewID);
try {
Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
mCursorDrawableRes.setAccessible(true);
mCursorDrawableRes.set(searchTextView, 0); //This sets the cursor resource ID to 0 or @null which will make it visible on white background
} catch (Exception e) {}
return super.onCreateOptionsMenu(menu);
}
代码示例来源:origin: stackoverflow.com
SearchView searchView = new SearchView(context);
AutoCompleteTextView search_text = (AutoCompleteTextView) searchView.findViewById(searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null));
search_text.setTextColor(Color.WHITE);
search_text.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.text_small));
代码示例来源:origin: square/assertj-android
public SearchViewAssert hasQueryHint(int resId) {
isNotNull();
return hasQueryHint(actual.getContext().getString(resId));
}
代码示例来源:origin: stackoverflow.com
SearchView searchView= (SearchView) findViewById(R.id.searchView1);
int id = searchView.getContext()
.getResources()
.getIdentifier("android:id/search_src_text", null, null);
TextView textView = (TextView) searchView.findViewById(id);
textView.setTextColor(Color.WHITE);
代码示例来源:origin: stackoverflow.com
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
searchView.findViewById(searchPlateId).setBackgroundResource(R.drawable.textfield_search_selected);
int voiceSearchPlateId = searchView.getContext().getResources().getIdentifier("android:id/submit_area", null, null);
searchView.findViewById(voiceSearchPlateId).setBackgroundResource(R.drawable.textfield_search_right_selected);
// change hint color
int searchTextViewId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
TextView searchTextView = (TextView) searchView.findViewById(searchTextViewId);
searchTextView.setHintTextColor(getResources().getColor(R.color.light_grey));
代码示例来源:origin: stackoverflow.com
SearchView searchView = (SearchView) ((AppCompatActivity) context).findViewById(R.id.search_view);
final EditText e = (EditText) sitesSearchView.findViewById(searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null));
try {
Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
mCursorDrawableRes.setAccessible(true);
mCursorDrawableRes.set(e, 0); //This sets the cursor resource ID to 0 or @null which will make it visible on white background
} catch (Exception ex) {}
代码示例来源:origin: andforce/iBeebo
public static void customActionBarSearchViewTextColor(SearchView searchView) {
int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
TextView textView = (TextView) searchView.findViewById(id);
textView.setTextColor(Color.WHITE);
}
代码示例来源:origin: stackoverflow.com
SearchView c = findViewById(R.id.searchView);
EditText e = (EditText)c.findViewById(c.getContext().getResources().getIdentifier("android:id/search_src_text", null, null));
e.setBackgroundColor(Color.BLACK); //←If you just want a color
e.setBackground(getResources().getDrawable(R.drawable.YOUR_DRAWABLE));
//↑ If you want a drawable ↑
代码示例来源:origin: stackoverflow.com
final SearchView searchView = (SearchView)findViewById(R.id.search);
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
EditText searchPlate = (EditText) searchView.findViewById(searchPlateId);
searchPlate.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
//Do something
}
return false;
});
代码示例来源:origin: stackoverflow.com
SearchManager searchManager = (SearchManager) a.getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = new android.widget.SearchView(a.getApplicationContext());
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
// Getting the 'search_plate' LinearLayout.
AutoCompleteTextView searchPlate = (AutoCompleteTextView) searchView.findViewById(searchPlateId);
// Setting background of 'search_plate' to earlier defined drawable.
searchPlate.setTextColor(Color.BLACK);
...
代码示例来源:origin: stackoverflow.com
public static void customizeSearchView(SearchView searchView) {
int searchTextViewId = searchView.getContext().getResources()
.getIdentifier("android:id/search_src_text", null, null);
AutoCompleteTextView searchTextView
= (AutoCompleteTextView) searchView.findViewById(searchTextViewId);
searchTextView.setTextSize(14);
searchTextView.setTextColor(Color.WHITE);
}
代码示例来源:origin: stackoverflow.com
final SearchView searchView = (SearchView)findViewById(R.id.search);
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
EditText searchPlate = (EditText) searchView.findViewById(searchPlateId);
searchPlate.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
//Do something
}
return false;
});
代码示例来源:origin: stackoverflow.com
SearchView searchView= (SearchView) findViewById(R.id.searchView1);
int id = searchView.getContext()
.getResources()
.getIdentifier("android:id/search_src_text", null, null);
TextView textView = (TextView) searchView.findViewById(id);
textView.setTextColor(Color.WHITE);
代码示例来源:origin: stackoverflow.com
SearchView searchView = (SearchView)menu.findItem(R.id.my_search_view).getActionView();
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
// Getting the 'search_plate' LinearLayout.
View searchPlate = searchView.findViewById(searchPlateId);
searchPlate.setBackgroundResource(R.drawable.textfield_searchview);
代码示例来源:origin: kingargyle/adt-leanback-support
public static void setSearchableInfo(View searchView, ComponentName searchableComponent) {
SearchView sv = ((SearchView) searchView);
SearchManager searchManager = (SearchManager)
sv.getContext().getSystemService(Context.SEARCH_SERVICE);
sv.setSearchableInfo(searchManager.getSearchableInfo(searchableComponent));
}
代码示例来源:origin: com.squareup.assertj/assertj-android
public SearchViewAssert hasQueryHint(int resId) {
isNotNull();
return hasQueryHint(actual.getContext().getString(resId));
}
代码示例来源:origin: stackoverflow.com
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
final int searchBarId = searchView.getContext().getResources().getIdentifier("android:id/search_bar", null, null);
LinearLayout searchBar = (LinearLayout) searchView.findViewById(searchBarId);
searchBar.setLayoutTransition(new LayoutTransition());
代码示例来源:origin: stackoverflow.com
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
//Get the ID for the search bar LinearLayout
int searchBarId = searchView.getContext().getResources().getIdentifier("android:id/search_bar", null, null);
//Get the search bar Linearlayout
LinearLayout searchBar = (LinearLayout)
searchView.findViewById(searchBarId);
//Give the Linearlayout a transition animation.
searchBar.setLayoutTransition(new LayoutTransition());
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.customer_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_customer_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setOnQueryTextListener(this);
//Applies white color on searchview text
int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
TextView textView = (TextView) searchView.findViewById(id);
textView.setTextColor(Color.WHITE);
return true;
}
内容来源于网络,如有侵权,请联系作者删除!