如题,想使用一个png图片做按钮项目中不能使用xml,也不能生成R.class布局完全使用java。不知道资源文件如何关联,求教

解决方案 »

  1.   

    通过语句在运行时动态创建按钮,就不需要xml文件啦
      

  2.   

    不用getViewByID,完全new 一个
      

  3.   


    是,但是如何链接图片文件到按钮呢? 一般不都是findViewById(R.id.icon)或者是getResources().getDrawable(id)关键是这个R.id.icon/id  我不知道如何在不使用R.class的时候去关联
      

  4.   

    可以将图片图片png文件放在assets目录下,通过getAssets()方面 可以获得图片文件的 
      

  5.   

    Button button = new Button(this);
    Drawable da = Drawable.createFromPath("/sdcard/1.png");
    button.setBackgroundDrawable(da);