下面列出了android.widget.EditText#setCompoundDrawablesWithIntrinsicBounds ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, null);
mEdit = (EditText) view.findViewById(R.id.edit);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
mEdit.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.drawable_left_selector,
R.drawable.drawable_top_selector,
R.drawable.drawable_right_selector,
R.drawable.drawable_bottom_selector);
}
mEdit1 = (EditText) view.findViewById(R.id.edit1);
mEdit1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.drawable_left_selector,
R.drawable.drawable_top_selector,
R.drawable.drawable_right_selector,
R.drawable.drawable_bottom_selector);
mText1 = (TextView) view.findViewById(R.id.text1);
mText1.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.drawable_left_selector),
getResources().getDrawable(R.drawable.drawable_top_selector),
getResources().getDrawable(R.drawable.drawable_right_selector),
getResources().getDrawable(R.drawable.drawable_bottom_selector));
return view;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, null);
mEdit = (EditText) view.findViewById(R.id.edit);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
mEdit.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.drawable_left_selector,
R.drawable.drawable_top_selector,
R.drawable.drawable_right_selector,
R.drawable.drawable_bottom_selector);
}
mEdit1 = (EditText) view.findViewById(R.id.edit1);
mEdit1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.drawable_left_selector,
R.drawable.drawable_top_selector,
R.drawable.drawable_right_selector,
R.drawable.drawable_bottom_selector);
mText1 = (TextView) view.findViewById(R.id.text1);
mText1.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.drawable_left_selector),
getResources().getDrawable(R.drawable.drawable_top_selector),
getResources().getDrawable(R.drawable.drawable_right_selector),
getResources().getDrawable(R.drawable.drawable_bottom_selector));
return view;
}
private void checkSimpleValid(EditText editText) {
if (editText.length() == 0) {
editText.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
} else if (editText.length() == 13) {
editText.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
ContextCompat.getDrawable(MainActivity.this, R.drawable.icon_valid),
null);
} else {
editText.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
ContextCompat.getDrawable(MainActivity.this, R.drawable.icon_invalid),
null);
}
}
private void createCustomUnitDialog() {
AlertDialog.Builder builder = new AlertDialog.
Builder(getActivity());
builder.setTitle("Create New Unit:");
Context context = getActivity();
final EditText filterEditText = new EditText(context);
final TextView textView = new TextView(context);
filterEditText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_search_white, 0, 0, 0);
filterEditText.setInputType(InputType.TYPE_CLASS_TEXT);
filterEditText.setHint("ie Dollars");
textView.setText("Unit Name:");
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(textView);
layout.addView(filterEditText);
builder.setView(layout);
builder.setNegativeButton(android.R.string.cancel, null);
AlertDialog alert = builder.create();
alert.show();
}
private void showOrHideSearchIcon(EditText view,boolean isShow,int imageRes){
if(isShow){
view.setCompoundDrawablesWithIntrinsicBounds(imageRes,0,0,0);
view.setPadding(0,0,0,0);//清除内边距
}else{
view.setCompoundDrawablesWithIntrinsicBounds(0,0,0,0);
view.setPadding(searchPaddingLeft,0,0,0);//设置左侧内边距
}
}
public static void clearFocus(EditText editText) {
editText.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
}