在此刻,我試圖運行的代碼,這行: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