PreferenceFragment界面默认是透明的
而其布局代码框架为 <PreferenceScreen> ... </PreferenceScreen>,背景色及透明度属性设置无效,可通过代码中setBackGroundResource实现,代码如下:
public class XXXFragment extends PreferenceFragment implements OnClickListener { @Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.note_preference_fragment);
getPreferenceManager().setSharedPreferencesName("mysetting");
} @Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
return true;
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
view.setBackgroundResource(R.color.white);
return view;
}
}
参考文章:http://www.crifan.com/android_preferencefragment_transparent_make_ui_messy/
另,重写preference fragment的方法参考:http://blog.csdn.net/chenshijun0101/article/details/8191429