第一步:在valuse下面新建xml文件 attrs.xml <?xml version="1.0" encoding="utf-8"?> <resources>
<declare-styleable name="RangeSeekbar"> // 第二步:在valus下新建属性 <attr name="letMargin" format="integer" /> </declare-styleable>
</resources>


第三步:在xml定义 定义一个xmlns: http://schemas.android.com/apk/res/ +包名 设置percent:letMargin="20" <com.example.androidtest.activity.view.PerCentView xmlns:percent=" http://schemas.android.com/apk/res/com.example.androidtest" percent:letMargin="20"
android:id="@+id/percent"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
/>

第四部:在自定义view中调用 public PerCentView(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RangeSeekbar); int left = typedArray.getInteger(R.styleable.RangeSeekbar_letMargin, 0); Log.e("tag", "dddd" + left); }

更多相关文章

  1. android 设置布局横屏竖屏
  2. Android(安卓)实现一个Service应用
  3. 使用ImageSpan图标不截断的方法
  4. Android自定义属性时format选项可以取用的值
  5. Android(安卓)Intent初步试用
  6. Tutorials ---- Hello, World
  7. android的AndroidManifest.xml文件介绍
  8. 初学Android,图形图像之在指定点(坐标)播放动画(三十五)
  9. Android(安卓)自定义SeekBar 实现分段显示不同背景颜色

随机推荐

  1. android倒计时封装(活动进入后台,倒计时依
  2. Android手机开发:ImageView使用和从内存读
  3. android 中添加Dialog
  4. LinearLayout中控件不能居右对齐
  5. android之Fragment-ListFragment的实践(三
  6. Android(安卓)记录一个好用的文件存储操
  7. android webview 获取geolocation
  8. Android设置重复文字水印背景
  9. 【Android】Android(安卓)permission 访
  10. android系统时间获取方式