最近我遇到了针对Android 8.0的EditText(HUAWEI P10 Plus)的问题:
代码如下:
public class MainActivity extends Activity {
Button button;
EditText edittext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button);
edittext = (EditText)findViewById(R.id.editText);
edittext.setTextColor(Color.BLUE);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edittext.setTextColor(Color.GREEN);
}
});
}
}
的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.smartway.testedittext"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
问题如下,由于某些原因,当我设置文本颜色时,EditText没有将颜色更改为Color.BLUE,它不会更改:
最有趣的是当我在某些时候键入很长的文本时,文本的颜色再次变为Color.BLUE:
当我将文本颜色设置为Color.BLUE并且仅在设备旋转后更改时,为什么不更改文本颜色? 有没有人面临同样的问题?如何解决它?
我已附加测试项目: TestEditText.zip