공유 환경 설정에 관한 모든 것을 이미 제자리에두고 내 활동 중 하나에서 logcat에서 이와 같은 공유 환경 설정 값을 검색 할 수 있습니다. 문자열 i = prefs.getString ("bgColor", "# f2345"); System.out.println (i);레이아웃에 공유 환경 설정 값을 설정하는 방법
그러나이 활동에서는 이와 같은 레이아웃을 사용하고 있습니다. SimpleCursorAdapter sca = new SimpleCursorAdapter (this, R.layout.country_row, c, from, to);
setListAdapter (sca); 지금은 이미 환경에서 점점 오전 값을 사용하여
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff000099"
android:background="#ffffff80"
android:padding="10dp"
android:textSize="16sp"
android:text="1964"/>
<TextView android:id="@+id/country"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#ffffff80"
android:background="#ff000099"
android:padding="10dp"
android:textSize="16sp"
android:text="Sweden"/>
, 내가 예를 들어 배경 색상이나 글꼴 여기를 변경하려면이 같다 "country_row는"내 XML 레이아웃 파일입니다 크기가 표시됩니다. 이제 내가 원하는 것은 내 레이아웃 xml 파일에 이러한 공유 우선 순위 값을 암시하는 것입니다. 나는 그것을 어떻게 할 수 있습니까?
사실 나는 이미 레이아웃 country_row.xml을 적용하고 커서 어댑터에서이
boolean i = prefs.getBoolean("fontBold", false);
System.out.println(i);
if (i){
TextView tv = (TextView)findViewById(R.id.year);
tv.setTypeface(null, Typeface.BOLD);//null pointer
}
같은 공유 환경 설정에서 값을 얻을 수 있습니다. 그렇다면이 레이아웃에 들어가는 환경 설정 값을 어떻게 사용할 수 있습니까? 체크 박스에서 가져 오는 불리언 값은 올바른 것으로 표시되어 인쇄됩니다. 그러나 위와 같이하려고하면 프로그램이 작동하지 않고 null 포인터 예외를 말하는 프로그램이 중단됩니다.
여기에 붙어있는 것은 .... 올바른 환경 설정 값을 얻지 만이를 사용하거나 기존 레이아웃에 적용하는 방법을 모르거나 다른 레이아웃을 만들어야합니다. .. 나는 그것에 관해 확실하지 않다.
시도했지만 작동하지 않았습니다. – SASM
무엇이 문제입니까? 색상을 저장하려면 int 변수를 사용하는 것이 좋습니다. – Huang
내가 공유 환경 설정에서 가져 오는 값은 내가 마지막으로 (on/off) 왼쪽으로 체크 박스를 볼 때 계속 유지됩니다. 또한 getBoolean 또는 getInt..but 값을 얻을 수 있습니다. 위에서 언급 한대로 country_row xml 레이아웃을 가지고 있습니다. 현재 내 질문에 apply.i도 findViewById (R.id.layoutID)를 얻는 방법을 알고 있습니다. 문제는 내가 가지고있는 환경 설정 값으로 font color 또는 bg color를 변경하는 방법이다. 그래서 country_row xml은이 변경된 레이아웃을 표시 할 것이다. – SASM