自定义布局中、在xml 自定义属性

例如:

<com.momo.PollNumberProgress    android:id="@+id/poll_progressbar1"    android:layout_width="match_parent"    android:layout_height="30dp"    android:paddingLeft="10dp"    android:visibility="gone"    app:pollBackground="@color/poll_progbar1" />
这里app:? 属于xml命名空间,

在你的根Layout

xmlns:app="http://schemas.android.com/apk/res-auto"

这里在给NumberProgress 自定义一个Background颜色、 app:pollBackground=“@color/progbar1” ?


在看看Java代码如何取出来

public PollNumberProgress(Context context) {    this(context, null);}public PollNumberProgress(Context context, AttributeSet attrs) {    this(context, attrs, R.attr.numberProgressBarStyle);}public PollNumberProgress(Context context, AttributeSet attrs, int defStyleAttr) {    super(context, attrs, defStyleAttr);    this.context = context;    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PollThemes, defStyleAttr, 0);    pollBackground = a.getColor(R.styleable.PollThemes_pollBackground, context.getResources().getColor(R.color.clear));    a.recycle();}

引用attrs:

<?xml version="1.0" encoding="utf-8"?><resources>    <declare-styleable name="PollThemes">        <attr name="numberProgressBarStyle" format="reference"/>        <attr name="pollBackground" format="color"></attr>    </declare-styleable></resources>
类型:

关于自定义布局,xml中配置属性(attrs)_第1张图片

关于Attrs用法:

参考:点击打开链接

参考:点击打开链接




更多相关文章

  1. ScrollView属性fillViewport解决android布局不能撑满全屏的问题
  2. Android ImageView的scaleType属性与adjustViewBounds属性
  3. 有关Android中EditText的一些属性
  4. Android自定义属性,format详解
  5. Android 错误 :TextView中属性ellipsize的 值为start、middle可能
  6. 优化布局在Android–减少过度渲染
  7. Android 自定义布局对话框避免全屏的设置
  8. Android RecyclerView网格布局的学习
  9. android中的一个属性动画,可以显示更多的一个案例

随机推荐

  1. android 6.0权限全面详细分析和解决方案
  2. Android获取SD卡视频音频文件
  3. 改变 Android EditText 的边框
  4. Android Sqlite数据库中判断某个表是否存
  5. 8.1 8321平台修改WIFI_ONLY总结
  6. linux tar.gz zip 解压缩 压缩命令
  7. Android app的音视频播放功能
  8. Android 判断当前网络 wifi ctwap(cmwap)
  9. Android轮播图封装,下拉刷新相结合
  10. android 监听短信和来电