Android View的构造方法
16lz
2021-01-23
public View(Context context);
public View(Context context, AttributeSet attrs);
public View(Context context, AttributeSet attrs, int defStyle);
public View(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes);
如果要在代码中new一个View对象,我们一般会使用第一个构造函数。
如果是在XML文件中声明的View,系统会默认调用第二个构造函数。
而对于第三个构造函数,我们在自己的代码中一般都没有去调用它。
前三个构造方法都会调用第三个构造方法
我们可以在AndroidManifest中指定主题,在构造Button时传递给defStyleAttr参数(构造函数中的第三个参数)
更多相关文章
- Android 两个Activity切换时回调函数调用顺序
- Android开发人员不得不收集的代码
- Android 实现SHA1加密算法代码
- Android 驱动之旅: 第一章 在Android 内核源代码工程中编写硬件驱
- android:布局参数,控件属性及各种xml的作用
- Android中WebView载入本地HTML代码并实现Java与JavaScript交互的
- 移植 C/C++ 代码至 Android 平台经验总结