특정 편집 텍스트가 비어 있거나 비어 있지 않을 때 버튼의 색상을 변경할 수 있는지 알고 싶습니다. edittext가 비어있을 때와 마찬가지로 버튼은 "ADD"라고 표시되고 비어 있지 않으면 "CHANGE"라고 표시됩니다. 누군가 나를 도울 수 있습니까? 미리 감사드립니다.
Button Text
세트 정보 :
if(editText.getText().toString.length()>0){
yourbutton.setText("Change");
}else{
yourbutton.setText("Add");
}
그리고 구현 EditText addTextChangedListener
하면
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence str, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence str, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable str) {
if(str.toString().trim().length()>0){
yourbutton.setText("Change");
}else{
yourbutton.setText("Add");
}
}
});
다음과 Button Text Color
같이 동적으로 설정할 수도 있습니다 .
yourbutton.setTextColor(Color.BLUE);
자세한 내용은 http://developer.android.com/reference/android/content/res/ColorStateList.html 로 이동 하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다