編輯:關於Android編程

如圖所示,有時候為了布局美觀,在搜索時沒有搜索按鈕,而是調用軟件盤上的按鈕。調用的實現只需要在XML在輸入框中加入android:imeOptions="actionSearch",調用軟鍵盤時,回車鍵就會顯示搜索二字。
然後調用 OnEditorActionListener,不是OnKeyListener
searchText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId ==EditorInfo.IME_ACTION_SEARCH){
// 先隱藏鍵盤
((InputMethodManager) searchText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(
getActivity()
.getCurrentFocus()
.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
//跳轉activity
Intent intent = new Intent();
intent.setClass(getActivity(), SearchResultActivity.class);
startActivity(intent);
return true;
}
return false;
}
});
Android編程小技巧
1、當有兩三個不同類的類且所用方法都一樣,需要完成不能的功能,而這個三個類可能都需要同另外一個類進行交互,而直接把這個類的應用到處傳遞也是很頭疼的,這時可用抽象了類來解決
Android文件夾管理器源碼實現
一、資源管理器介紹現在在一些移動終端上面都會有自帶的資源管理器,其實其並非是Android系統自帶,而是手機產商與app開發商的合作而導致融合,借助第三方的開發軟件預裝在
Android MVVM
1、Android DataBinding:再見MVP,你好MVVM當我們談到android應用程序的架構模式時,MVP一直是占主流的地位。就像 Ted Mosby, N
ViewPager+Fragment+ListView打造新聞列表
今天接觸到了Fragment碎片,也是現在編寫APP的主流道具。那麼今天我用ViewPager、Fragment和ListView做了一個新聞列表,分享給大家。效果圖裡上