- CompoundButton 源码分析
- LinearLayout 源码分析
- SearchView 源码解析
- LruCache 源码解析
- ViewDragHelper 源码解析
- BottomSheets 源码解析
- Media Player 源码分析
- NavigationView 源码解析
- Service 源码解析
- Binder 源码分析
- Android 应用 Preference 相关及源码浅析 SharePreferences 篇
- ScrollView 源码解析
- Handler 源码解析
- NestedScrollView 源码解析
- SQLiteOpenHelper/SQLiteDatabase/Cursor 源码解析
- Bundle 源码解析
- LocalBroadcastManager 源码解析
- Toast 源码解析
- TextInputLayout
- LayoutInflater 和 LayoutInflaterCompat 源码解析
- TextView 源码解析
- NestedScrolling 事件机制源码解析
- ViewGroup 源码解析
- StaticLayout 源码分析
- AtomicFile 源码解析
- AtomicFile 源码解析
- Spannable 源码分析
- Notification 之 Android 5.0 实现原理
- CoordinatorLayout 源码分析
- Scroller 源码解析
- SwipeRefreshLayout 源码分析
- FloatingActionButton 源码解析
- AsyncTask 源码分析
- TabLayout 源码解析
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
1.3 构造方法和自定义
接下来看构造方法 public SearchView(Context context, AttributeSet attrs, int defStyleAttr) , v7 的 SearchView 并不是用 TypedArray 而是使用 TintTypedArray ,看了源码发现 TintTypedArray 里有个: private final TypedArray mWrapped; 所以主要还是 TypedArray ,不同点是 getDrawable(int index) 和新加的 getDrawableIfKnown(int index) 方法, 并在满足条件下会调用 AppCompatDrawableManager.get().getDrawable(mContext, resourceId) 。
为了能更好的自定义, SearchView 的 layout 也是可以指定的,不过自定义的 layout 必须包括上面那些控件,同时 id 也是指定的, 不然后面会报错,因为 findViewById(id) 无法找到各自控件,然后调用控件方法的时候就。。。
构造方法最后是更新控件状态, mIconifiedByDefault 默认是 true 的, setIconifiedByDefault(boolean iconified) 改变值后也会执行如下方法:
public void setIconifiedByDefault(boolean iconified) {
if (mIconifiedByDefault == iconified) return;
mIconifiedByDefault = iconified;
//更新组件
updateViewsVisibility(iconified);
updateQueryHint();
}所以 setIconifiedByDefault(false) 会让 SearchView 一直呈现展开状态,并且输入框内 icon 也会不显示。具体方法如下,该方法在 updateQueryHint() 中被调用:
private CharSequence getDecoratedHint(CharSequence hintText) {
//如果 mIconifiedByDefault 为 false 或者 mSearchHintIcon 为 null
//将不会添加搜索 icon 到提示 hint 中
if (!mIconifiedByDefault || mSearchHintIcon == null) {
return hintText;
}
final int textSize = (int) (mSearchSrcTextView.getTextSize() * 1.25);
mSearchHintIcon.setBounds(0, 0, textSize, textSize);
final SpannableStringBuilder ssb = new SpannableStringBuilder(" ");
ssb.setSpan(new ImageSpan(mSearchHintIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.append(hintText);
return ssb;
}
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论