在此刻,我试图运行的代码,这行:Android Studio中,共享偏好设置文本颜色
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Tell me");
setContentView(R.layout.activity_post);
getSupportActionBar().setDisplayHomeAsUpEnabled(true)
;
editText = (EditText) findViewById(R.id.editText1);
textView = (TextView) findViewById(R.id.textView);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String s = sharedPreferences.getString("font_list", "null");
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/" + s);
editText.setTypeface(face);
String s2 = sharedPreferences.getString("font_size", "8");
editText.setTextSize(Float.parseFloat(s2));
String s3 = sharedPreferences.getString("font_color", "#000");
editText.setTextColor(Color.parseColor(s3));
// File directory = new File(path);
// directory.mkdirs();
}
- 我想设置并存储的色彩,用户的选择,让他们输入在那种颜色下,但每当我尝试运行应用程序或在应用程序中执行任何操作时,它都会因为setTextColor函数和字符串中的sharePreferences而崩溃。
这里是logcat的图像
你可以分享你的logcat吗? – Nhan
一切工作正常的设置文本的字体和大小。它由于某种原因运行设置文本颜色时崩溃。 – EzioBahin
logcat?不知道那是什么,我是新的android工作室。 – EzioBahin