searchView = findViewById(R.id.searchicon);
searchView.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.getLayoutParams().width = 1800;
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
return false;
}
});
我想减少searchview
中OnCloseListener
的宽度,如何获得该视图?
答案 0 :(得分:1)
绘制完布局以改变尺寸和形状后,您必须调用requestLayout()
所以使用
searchView.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.getLayoutParams().width = 1800;
v.invalidate(); // for redrawing
v.requestLayout(); // for dimension change
}
});
封闭使用
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
searchView.requestLayout(); // make sure to declare search view outside oncreate or use local final variable
// or this //findViewById(R.id.searchicon).requestLayout(); // for dimension change
return false;
}
});
Reference: Usage of forceLayout(), requestLayout() and invalidate()