在mainActivity我採取hexString然後開始新的活動,併發送hexString到它 並改變背景顏色與此十六進制字符串。 我需要知道是否有背景顏色方法可以採取參數hexString或長。改變背景顏色以十六進制
代碼:
String colorValue = getIntent().getStringExtra("colorHex");
findViewById(R.id.layout1).setBackgroundColor(Color.parseColor(colorValue));//want change in the argument or if there's another method.
不能工作,使新的活動停止,如果我插入六角前0xFFF的。 – Magician
嘗試使用#,像這樣'public static int parseColor(「#0xfff」)' 使用try和catch,因爲**如果字符串不能被解析,拋出一個IllegalArgumentException異常** – Dario
當它開始新的活動。 – Magician