zoukankan      html  css  js  c++  java
  • [转载]android工程中引入另一个工程中的资源

    在项目中可能遇到这样的问题:项目过大,于是细分为N个子模块来做,每个模块都是不同的工程。涉及到activity传数据时,可以用intent等方法来解决。但是如果涉及到要共用资源,而又不能像传统java程序那样打成jar包,比如程序中有大量自定义view,而这些自定义view都引用了的一些资源文件时,就可以用这个方法。

    工程一:MyViews

    代码如下:

    public class MyTextView extends TextView{

     public MyTextView(Context context) {
      super(context);
      // TODO Auto-generated constructor stub
      this.setBackgroundColor(Color.BLUE);
      this.setText(context.getResources().getString(R.string.test_view));
     }

    }

    对工程一,右键-->properties,勾选Is Library,确定即可。

    [转载]android工程中引入另一个工程中的资源

    [转载]android工程中引入另一个工程中的资源

    工程二:TestActivity

    首先对工程二,右键-->properties-->android-->Add-->MyViews,然后确定即可

    代码如下:

    public class TestActivity extends Activity {
       
     private MyTextView mtv;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mtv=new MyTextView(this);
            setContentView(mtv);
        }
    }

    运行工程二,可发现成功调用了工程一中的MyTextView

  • 相关阅读:
    Angular2 组件通信
    vue跨组件通信的几种方法
    Angular React 和 Vue的比较
    vue对比其他框架
    ReactJS 生命周期、数据流与事件
    LeetCode 1089. 复写零(Duplicate Zeros) 72
    LeetCode 421. 数组中两个数的最大异或值(Maximum XOR of Two Numbers in an Array) 71
    12
    11
    10
  • 原文地址:https://www.cnblogs.com/android-blogs/p/5336759.html
Copyright © 2011-2022 走看看