imageview setbackgroundcolor is not working in android

天大地大妈咪最大 提交于 2019-12-11 10:11:55

问题


I asked a question about ui updating in preferencelistfragment in android.(How to change imageview background color in a preference in android?)

And it works for android 4.1.2 version. I test it also in 2.3.3, 3.0 and 4.3 android versions and i see that it is not working in these versions. To make question simple, i would like to ask why the code below is not working on these versions:

public class SettingsIncomingSearchFragment extends PreferenceListFragment 
implements SharedPreferences.OnSharedPreferenceChangeListener
{
    @Override
    public void onCreate(Bundle icicle) 
    {
     <!-- other codes -->
     setBackgroundColor() ;  
     <!-- other codes -->
    }  

private void setBackgroundColor() {
    // TODO Auto-generated method stub
    LinearLayout mainlayout ;
    LinearLayout sublayout ;
    View view ;
    ImageView img ;
    SharedPreferences sp ;
    sp = ctx.getSharedPreferences(SHARED_PREFS_NAME, ctx.MODE_PRIVATE);

       LayoutInflater inflater =  (LayoutInflater)
                getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        view = inflater.inflate(R.layout.rectangle_layout, null);

        mainlayout = (LinearLayout)view.findViewById(R.id.rectangle_main_layout_ll);

        sublayout = (LinearLayout)mainlayout.findViewById(R.id.rectangle_layout_ll);    

        String defValue = null ;      
        defValue = sp.getString("incomingsearchbackgroundcolor", String.valueOf(Color.BLACK));
        if(defValue != null)
        {
        img = (ImageView)sublayout.findViewById(R.id.iv_priority);
        img.setBackgroundColor(Integer.parseInt(defValue));

        }

}

Thanks!

来源:https://stackoverflow.com/questions/21360959/imageview-setbackgroundcolor-is-not-working-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!