本文整理汇总了Java中android.view.View.setFocusable方法的典型用法代码示例。如果您正苦于以下问题:Java View.setFocusable方法的具体用法?Java View.setFocusable怎么用?Java View.setFocusable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.setFocusable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isShouldHideInput
import android.view.View; //导入方法依赖的package包/类
public boolean isShouldHideInput(View v, MotionEvent event) {
if (v != null && (v instanceof EditText)) {
int[] leftTop = {0, 0};
//获取输入框当前的location位置
v.getLocationInWindow(leftTop);
int left = leftTop[0];
int top = leftTop[1];
int bottom = top + v.getHeight();
int right = left + v.getWidth();
if (event.getX() > left && event.getX() < right
&& event.getY() > top && event.getY() < bottom) {
// 点击的是输入框区域,保留点击EditText的事件
return false;
} else {
//使EditText触发一次失去焦点事件
v.setFocusable(false);
// v.setFocusable(true); //这里不需要是因为下面一句代码会同时实现这个功能
v.setFocusableInTouchMode(true);
return true;
}
}
return false;
}
示例2: addFocusChangeListener
import android.view.View; //导入方法依赖的package包/类
protected final void addFocusChangeListener(OnFocusChangeListener l){
View view;
if(l != null && (view = getRealView()) != null) {
if( mFocusChangeListeners == null){
mFocusChangeListeners = new ArrayList<>();
view.setFocusable(true);
view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
for (OnFocusChangeListener listener : mFocusChangeListeners){
if(listener != null){
listener.onFocusChange(hasFocus);
}
}
}
});
}
mFocusChangeListeners.add(l);
}
}
示例3: addTab
import android.view.View; //导入方法依赖的package包/类
private void addTab(final int position, View tab) {
tab.setFocusable(true);
tab.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (pager.getCurrentItem() == position && onTabClickListener != null) {
onTabClickListener.onCurrentTabClicked(position);
} else {
pager.setCurrentItem(position, true);
}
}
});
addTabDoubleTapListener(position, tab);
tab.setPadding(tabPadding, 0, tabPadding, 0);
tabsContainer.addView(tab, position, tabViewLayoutParams);
}
示例4: onCreateViewHolder
import android.view.View; //导入方法依赖的package包/类
@Override
public ForecastAdapterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
if ( viewGroup instanceof RecyclerView ) {
int layoutId = -1;
switch (viewType) {
case VIEW_TYPE_TODAY: {
layoutId = R.layout.list_item_forecast_today;
break;
}
case VIEW_TYPE_FUTURE_DAY: {
layoutId = R.layout.list_item_forecast;
break;
}
}
View view = LayoutInflater.from(viewGroup.getContext()).inflate(layoutId, viewGroup, false);
view.setFocusable(true);
return new ForecastAdapterViewHolder(view);
} else {
throw new RuntimeException("Not bound to RecyclerView");
}
}
示例5: onClick
import android.view.View; //导入方法依赖的package包/类
@Override
public void onClick(final View v) {
if (!v.isFocused()) {
v.setFocusable(true);
v.setFocusableInTouchMode(true);
v.requestFocus();
GuiUtils.setKeypadVisibility(getActivity(), (EditText)v, View.VISIBLE);
// 這裡會先delay再送出event,要不然softkeyboard不會出現
/*(new Handler()).postDelayed(new Runnable() {
public void run() {
v.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN , 0, 0, 0));
v.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP , 0, 0, 0));
}
}, 200);*/
}
}
示例6: disable
import android.view.View; //导入方法依赖的package包/类
/**
* Helper function to disable a ViewGroup and all it's children. This draws a new view with z-ordering of integer max
* that consumes all touch events.
* @param viewGroup
*/
public static void disable(ViewGroup viewGroup){
View view = new View(viewGroup.getContext());
viewGroup.addView(view);
view.setTag(DISABLE);
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = MATCH_PARENT;
params.width = MATCH_PARENT;
view.setLayoutParams(params);
view.setClickable(true);
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.setBackgroundColor(Color.TRANSPARENT);
if (Build.VERSION.SDK_INT >= 21) {
view.setTranslationZ(Integer.MAX_VALUE);
}
viewGroup.bringChildToFront(view);
}
示例7: addTab
import android.view.View; //导入方法依赖的package包/类
private void addTab(final int position, View tab) {
tab.setFocusable(true);
tab.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
pager.setCurrentItem(position);
// XXX INDSAT TIL DR RADIO: “Nulstil” visning, når der tappes på kanalikon i toppen, så man kommer tilbage til NU-visning (belejligt hvis man har scrollet op el. ned i epg liste)
//if (delegatePageListener != null && delegatePageListener instanceof Kanaler_frag) {
// ((Kanaler_frag) delegatePageListener).klikPåFane(position);
//}
// Grimt hack, men desværre umuligt at gøre på en anden måde
if (Kanal_frag.senesteSynligeFragment != null) {
Kanal_frag.senesteSynligeFragment.rulBlødtTilAktuelUdsendelse();
}
// XXX INDSAT TIL DR RADIO slut
}
});
tab.setPadding(tabPadding, 0, tabPadding, 0);
tab.setMinimumWidth(minBredde);
tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}
示例8: onCreateViewHolder
import android.view.View; //导入方法依赖的package包/类
/**
* This gets called when each new ViewHolder is created. This happens when the RecyclerView
* is laid out. Enough ViewHolders will be created to fill the screen and allow for scrolling.
*
* @param viewGroup The ViewGroup that these ViewHolders are contained within.
* @param viewType If your RecyclerView has more than one type of item (like ours does) you
* can use this viewType integer to provide a different layout. See
* {@link android.support.v7.widget.RecyclerView.Adapter#getItemViewType(int)}
* for more details.
* @return A new ForecastAdapterViewHolder that holds the View for each list item
*/
@Override
public ForecastAdapterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View view = LayoutInflater
.from(mContext)
.inflate(R.layout.forecast_list_item, viewGroup, false);
view.setFocusable(true);
return new ForecastAdapterViewHolder(view);
}
示例9: onBindViewHolder
import android.view.View; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
HeaderItem headerItem = ((ListRow) item).getHeaderItem();
View rootView = viewHolder.view;
rootView.setFocusable(true);
ImageView iconView = (ImageView) rootView.findViewById(R.id.header_icon);
Drawable icon = rootView.getResources().getDrawable(R.drawable.icon_movies, null);
iconView.setImageDrawable(icon);
TextView label = (TextView) rootView.findViewById(R.id.header_label);
label.setText(headerItem.getName());
}
示例10: setAccessibilityIgnore
import android.view.View; //导入方法依赖的package包/类
public static void setAccessibilityIgnore(View view) {
view.setClickable(false);
view.setFocusable(false);
view.setContentDescription("");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
}
}
示例11: setCurrentItem
import android.view.View; //导入方法依赖的package包/类
/**
* 切换 tab
* @param position
*/
public void setCurrentItem(int position) {
for (int i = 0; i < tabCount; i++) {
View tab = tabsContainer.getChildAt(i);
tab.setFocusable(true);
currentPosition = position;
pager.setCurrentItem(position);
}
}
示例12: addTab
import android.view.View; //导入方法依赖的package包/类
private void addTab(final int position, View tab) {
tab.setFocusable(true);
tab.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
pager.setCurrentItem(position);
}
});
tab.setPadding(tabPadding, 0, tabPadding, 0);
tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}
示例13: onCreateViewHolder
import android.view.View; //导入方法依赖的package包/类
/**
* This gets called when each new ViewHolder is created. This happens when the RecyclerView
* is laid out. Enough ViewHolders will be created to fill the screen and allow for scrolling.
*
* @param viewGroup The ViewGroup that these ViewHolders are contained within.
* @param viewType If your RecyclerView has more than one type of item (like ours does) you
* can use this viewType integer to provide a different layout. See
* {@link android.support.v7.widget.RecyclerView.Adapter#getItemViewType(int)}
* for more details.
* @return A new ForecastAdapterViewHolder that holds the View for each list item
*/
@Override
public ForecastAdapterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
int layoutId;
switch (viewType) {
case VIEW_TYPE_TODAY: {
layoutId = R.layout.list_item_forecast_today;
break;
}
case VIEW_TYPE_FUTURE_DAY: {
layoutId = R.layout.forecast_list_item;
break;
}
default:
throw new IllegalArgumentException("Invalid view type, value of " + viewType);
}
View view = LayoutInflater.from(mContext).inflate(layoutId, viewGroup, false);
view.setFocusable(true);
return new ForecastAdapterViewHolder(view);
}
示例14: addTab
import android.view.View; //导入方法依赖的package包/类
private void addTab(final int position, View tab) {
tab.setFocusable(true);
tab.setTag(TAB_INDEX, position);
tab.setOnClickListener(mTabItemClick);
int left = Math.max(mItemMinPaddingHorizontal, tab.getPaddingLeft());
int top = Math.max(mItemMinPaddingTop, tab.getPaddingTop());
int right = Math.max(mItemMinPaddingHorizontal, tab.getPaddingRight());
int bottom = Math.max(mItemMinPaddingBottom, tab.getPaddingBottom());
tab.setPadding(left, top, right, bottom);
if (tab.getLayoutParams() == null) {
addView(tab, position, mItemLayoutParams);
} else {
addView(tab, position);
}
}
示例15: showSoftKeyboard
import android.view.View; //导入方法依赖的package包/类
/**
* 显示软键盘
*
* @param view
*/
public static void showSoftKeyboard(View view) {
Context context = view.getContext();
InputMethodManager imm = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.requestFocus();
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}