下面列出了怎么用android.util.AttributeSet的API类实例代码及写法,或者点击链接到github查看源代码。
public InfiniteCycleManager(
final Context context,
final ViewPageable viewPageable,
final AttributeSet attributeSet
) {
mContext = context;
mIsVertical = viewPageable instanceof VerticalViewPager;
mViewPageable = viewPageable;
mCastViewPageable = (View) viewPageable;
// Set default InfiniteViewPager
mViewPageable.setPageTransformer(false, getInfinityCyclePageTransformer());
mViewPageable.addOnPageChangeListener(mInfinityCyclePageChangeListener);
mViewPageable.setClipChildren(DEFAULT_DISABLE_FLAG);
mViewPageable.setDrawingCacheEnabled(DEFAULT_DISABLE_FLAG);
mViewPageable.setWillNotCacheDrawing(DEFAULT_ENABLE_FLAG);
mViewPageable.setPageMargin(DEFAULT_PAGE_MARGIN);
mViewPageable.setOffscreenPageLimit(DEFAULT_OFFSCREEN_PAGE_LIMIT);
mViewPageable.setOverScrollMode(OVER_SCROLL_NEVER);
// Reset scroller and process attribute set
resetScroller();
processAttributeSet(attributeSet);
}
public JazzyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.mEnabled = true;
this.mFadeEnabled = false;
this.mOutlineEnabled = false;
this.mEffect = TransitionEffect.Standard;
this.mObjs = new LinkedHashMap();
this.jvpInnerHandler = null;
this.mMatrix = new Matrix();
this.mCamera = new Camera();
this.mTempFloat2 = new float[2];
setClipChildren(false);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.JazzyViewPager);
setTransitionEffect(TransitionEffect.valueOf(getResources().getStringArray(R.array.jazzy_effects)[ta.getInt(0, 0)]));
setFadeEnabled(ta.getBoolean(1, false));
setOutlineEnabled(ta.getBoolean(2, false));
setOutlineColor(ta.getColor(3, -1));
switch (1.$SwitchMap$com$letv$android$client$widget$JazzyViewPager$TransitionEffect[this.mEffect.ordinal()]) {
case 1:
case 2:
setFadeEnabled(true);
break;
}
ta.recycle();
}
@Override
public View onCreateView(String name, Context context, AttributeSet attrs)
{
View view = null;
if (name.equals(LAYOUT_FRAMELAYOUT))
{
view = new AutoFrameLayout(context, attrs);
}
if (name.equals(LAYOUT_LINEARLAYOUT))
{
view = new AutoLinearLayout(context, attrs);
}
if (name.equals(LAYOUT_RELATIVELAYOUT))
{
view = new AutoRelativeLayout(context, attrs);
}
if (name.equals(CARD_VIEW))
{
view = new AutoCardView(context, attrs);
}
if (view != null) return view;
return super.onCreateView(name, context, attrs);
}
public SwitchRowView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwitchRowView);
CharSequence title = a.getText(R.styleable.SwitchRowView_title);
subtitle = a.getText(R.styleable.SwitchRowView_subtitle);
subtitleOn = a.getText(R.styleable.SwitchRowView_subtitleOn);
subtitleOff = a.getText(R.styleable.SwitchRowView_subtitleOff);
a.recycle();
LayoutInflater.from(context).inflate(R.layout.switch_row_view, this);
titleView = findViewById(R.id.switch_row_title);
subtitleView = findViewById(R.id.switch_row_subtitle);
switchMaterial = findViewById(R.id.switch_row_switch);
titleView.setText(title);
updateSubtitle();
switchMaterial.setOnCheckedChangeListener((buttonView, isChecked) -> updateSubtitle());
}
public PopupCircleView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = (Activity) context;
mHandler = new Handler(Looper.getMainLooper(), this);
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CircleMenu, 0, 0);
initDefaultParam();
mRadius = a.getDimensionPixelSize(R.styleable.CircleMenu_pc_radius, (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, 100, getResources().getDisplayMetrics()));
mAnimDuration = a.getInt(R.styleable.CircleMenu_pc_anim_duration, 250);
mOpenDirection = a.getInt(R.styleable.CircleMenu_pc_open_direction, UNDEFIEN);
a.recycle();
init();
}
@Override
protected final GridView createRefreshableView(Context context, AttributeSet attrs) {
final GridView gv;
if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) {
gv = new InternalGridViewSDK9(context, attrs);
} else {
gv = new InternalGridView(context, attrs);
}
// Use Generated ID (from res/values/ids.xml)
gv.setId(R.id.gridview);
return gv;
}
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (isInEditMode()) return;
//Load defaults from resources
final Resources res = getResources();
final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);
//Retrieve styles attributes
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);
mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
mPaintPageFill.setStyle(Style.FILL);
mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
mPaintStroke.setStyle(Style.STROKE);
mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
mPaintFill.setStyle(Style.FILL);
mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);
Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
if (background != null) {
setBackgroundDrawable(background);
}
a.recycle();
final ViewConfiguration configuration = ViewConfiguration.get(context);
mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
public void setup(AttributeSet attrs) {
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Style.FILL);
paint.setStrokeCap(Cap.ROUND);
springSystem = SpringSystem.create();
spring = springSystem.createSpring();
spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(50, 7));
this.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
toggle(defaultAnimate);
}
});
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ToggleButton);
offBorderColor = typedArray.getColor(R.styleable.ToggleButton_offBorderColor, offBorderColor);
onColor = typedArray.getColor(R.styleable.ToggleButton_onColor, onColor);
spotColor = typedArray.getColor(R.styleable.ToggleButton_spotColor, spotColor);
offColor = typedArray.getColor(R.styleable.ToggleButton_offColor, offColor);
borderWidth = typedArray.getDimensionPixelSize(R.styleable.ToggleButton_borderWidth1, borderWidth);
defaultAnimate = typedArray.getBoolean(R.styleable.ToggleButton_animate, defaultAnimate);
isDefaultOn = typedArray.getBoolean(R.styleable.ToggleButton_isDefaultOn, isDefaultOn);
typedArray.recycle();
borderColor = offBorderColor;
if (isDefaultOn) {
toggleOn();
}
}
public CallSliderAnswer(
Context context,
AttributeSet attrs,
int defStyle
) {
super(context, attrs, defStyle);
LayoutInflater.from(getContext()).inflate(R.layout.call_slider_answer, this, true);
mCallImage = findViewById(R.id.call_slider_img);
if (mCallImage != null) {
mCallImage.setOnTouchListener(this);
}
mCallText = findViewById(R.id.call_slider_text);
}
@SuppressLint("JavascriptInterface")
@Override
protected WebView createRefreshableView(Context context, AttributeSet attrs) {
WebView webView = super.createRefreshableView(context, attrs);
// Need to add JS Interface so we can get the response back
mJsCallback = new JsValueCallback();
webView.addJavascriptInterface(mJsCallback, JS_INTERFACE_PKG);
return webView;
}
private void init(Context context, AttributeSet attrs) {
mNormalDrawable = new StateListDrawable();
if (attrs != null) {
initAttributes(context, attrs);
}
mNormalText = getText().toString();
setBackgroundCompat(mNormalDrawable);
getFont(context);
}
public DrawingBoardView(Context context, AttributeSet attributeSet)
{
super(context, attributeSet);
this.context = context;
brushGestureListener = new BrushGestureListener();
brushGestureDetector = new GestureDetector(context,
brushGestureListener);
}
public KeyboardAwareLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
final int statusBarRes = getResources().getIdentifier("status_bar_height", "dimen", "android");
minKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_keyboard_size);
minCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_size);
defaultCustomKeyboardSize = getResources().getDimensionPixelSize(R.dimen.default_custom_keyboard_size);
minCustomKeyboardTopMargin = getResources().getDimensionPixelSize(R.dimen.min_custom_keyboard_top_margin);
statusBarHeight = statusBarRes > 0 ? getResources().getDimensionPixelSize(statusBarRes) : 0;
viewInset = getViewInset();
}
private void getAttrs(AttributeSet attributeSet) {
TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.RibbonTag);
try {
setTypeArray(typedArray);
} finally {
typedArray.recycle();
}
}
private void initView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
final TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.ClipImageView,
defStyleAttr, defStyleRes);
final int type = custom.getInt(R.styleable.ClipImageView_civClipType, 0);
final float radius = custom.getDimension(R.styleable.ClipImageView_civRoundRectRadius,
0);
final float width = custom.getDimension(R.styleable.ClipImageView_civBorderWidth,
0);
final ColorStateList color = custom.getColorStateList(
R.styleable.ClipImageView_civBorderColor);
final String name = custom.getString(R.styleable.ClipImageView_civClipOutlineProvider);
custom.recycle();
mClipPath.setFillType(Path.FillType.EVEN_ODD);
mOutlinePath.setFillType(Path.FillType.EVEN_ODD);
switch (type) {
default:
break;
case 1:
mProvider = ClipOutlineProvider.CIRCLE;
break;
case 2:
mProvider = ClipOutlineProvider.OVAL;
break;
case 3:
mProvider = ClipOutlineProvider.FULL_ROUND_RECT;
break;
case 4:
mProvider = new RoundRectClipOutlineProvider(radius);
break;
}
final ClipOutlineProvider provider = ConstructorHelper.newInstance(context, name,
isInEditMode(), this, ClipOutlineProvider.class,
attrs, defStyleAttr, defStyleRes);
if (provider != null)
mProvider = provider;
mBorderWidth = width;
mBorderColor = color;
}
public LinkTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public DragItemRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
init();
}
public SignView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public LinearHHClassifyView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public PhotoView(Context context, AttributeSet attr) {
this(context, attr, 0);
}
public TimeEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public OverScrollableListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setOverScrollMode(OVER_SCROLL_ALWAYS);
}
public SwipeableRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs, 0);
}
public ParallaxHorizontalScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public ColorPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initAttrs(attrs, defStyle);
}
public MovieView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public IconTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
this.setTypeface(Typeface.createFromAsset(context.getAssets(), "iconfont.ttf"));
}
public ArcMenu(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
100, getResources().getDisplayMetrics());
// 获取自定义属性的值;
TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
R.styleable.ArcMenu, defStyle, 0);
int pos = a.getInt(R.styleable.ArcMenu_position, POS_RIGHT_BOTTOM);
switch (pos) {
case POS_LEFT_TOP:
mPosition = Position.LEFT_TOP;
break;
case POS_LEFT_BOTTOM:
mPosition = Position.LEFT_BOTTOM;
break;
case POS_RIGHT_TOP:
mPosition = Position.RIGHT_TOP;
break;
case POS_RIGHT_BOTTOM:
mPosition = Position.RIGHT_BOTTOM;
break;
}
mRadius = (int) a.getDimension(R.styleable.ArcMenu_radius, TypedValue
.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
getResources().getDisplayMetrics()));
// Log.i("TAG", "position=" + mPosition + ",radius=" + mRadius);
a.recycle();
}
@NonNull
@Override
protected AppCompatCheckBox createCheckBox(Context context, AttributeSet attrs) {
return new MaterialCheckBox(context, attrs);
}
public BadgeView(Context context, AttributeSet attrs, int defStyle) {
this(context, attrs, defStyle, null, 0);
}