Skip to content
This repository has been archived by the owner on Apr 12, 2018. It is now read-only.

Commit

Permalink
1、增加RadiusEditText控件修改效果截图
Browse files Browse the repository at this point in the history
  • Loading branch information
胡涛 committed Feb 13, 2017
1 parent 5bc4f9a commit 89c1756
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--------------------------
####一、简介:

一个用于需要圆角矩形框背景的TextView或Layout的情况,减少直接使用时引入的shape资源文件,包括RadiusTextView,RadiusLinearLayout,RadiusRelativeLayout,RadiusLinearLayout
一个用于需要圆角矩形框背景的TextView或Layout的情况,减少直接使用时引入的shape资源文件,包括RadiusTextView,RadiusEditText,RadiusLinearLayout,RadiusRelativeLayout,RadiusLinearLayout
该库为[FlycoRoundView](https://github.com/H07000223/FlycoRoundView)扩展,主要增加不可点击状态属性并修改部分属性命名方式,使用方式参照layout_main.

**1.1 Gradle集成**
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@
rv:rv_textColor="#03A9F4"
rv:rv_textPressedColor="#ffffff"/>

<com.aries.ui.view.radius.RadiusEditText
android:id="@+id/ret_radius"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="RadiusEditText"
android:paddingBottom="10dp"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:paddingTop="10dp"
android:textColor="#03A9F4"
android:textCursorDrawable="@null"
rv:rv_backgroundColor="@android:color/white"
rv:rv_radius="10dp"
rv:rv_strokeColor="#03A9F4"
rv:rv_strokeWidth="1dp"/>

<com.aries.ui.view.radius.RadiusTextView
android:id="@+id/rtv_radius"
android:layout_width="wrap_content"
Expand All @@ -95,6 +115,7 @@
android:paddingTop="10dp"
android:text="RadiusTextView"
rv:rv_backgroundColor="#F6CE59"
rv:rv_backgroundPressedColor="#F6C"
rv:rv_radius="10dp"
rv:rv_textColor="#383838"/>

Expand Down Expand Up @@ -130,6 +151,7 @@
android:text="topRightRadius"
android:textColor="#ffffff"
rv:rv_backgroundColor="#F08A5D"
rv:rv_backgroundPressedColor="#F08A4D"
rv:rv_rippleEnable="true"
rv:rv_topRightRadius="10dp"/>
</LinearLayout>
Expand Down
56 changes: 56 additions & 0 deletions library/src/main/java/com/aries/ui/view/radius/RadiusEditText.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.aries.ui.view.radius;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;

/**
* Created: AriesHoo on 2017-02-13 16:10
* Function:用于需要圆角矩形框背景的EditText的情况,减少直接使用TextView时引入的shape资源文件
* Desc:
*/
public class RadiusEditText extends EditText {
private RadiusViewDelegate delegate;

public RadiusEditText(Context context) {
this(context, null);
}

public RadiusEditText(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public RadiusEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
delegate = new RadiusViewDelegate(this, context, attrs);
}

/**
* use delegate to set attr
*/
public RadiusViewDelegate getDelegate() {
return delegate;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (delegate.getWidthHeightEqualEnable() && getWidth() > 0 && getHeight() > 0) {
int max = Math.max(getWidth(), getHeight());
int measureSpec = MeasureSpec.makeMeasureSpec(max, MeasureSpec.EXACTLY);
super.onMeasure(measureSpec, measureSpec);
return;
}

super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (delegate.getRadiusHalfHeightEnable()) {
delegate.setRadius(getHeight() / 2);
} else {
delegate.setBgSelector();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

/**
Expand Down Expand Up @@ -70,7 +71,6 @@ private void obtainAttributes(Context context, AttributeSet attrs) {
bottomLeftRadius = ta.getDimensionPixelSize(R.styleable.RadiusTextView_rv_bottomLeftRadius, 0);
bottomRightRadius = ta.getDimensionPixelSize(R.styleable.RadiusTextView_rv_bottomRightRadius, 0);
isRippleEnable = ta.getBoolean(R.styleable.RadiusTextView_rv_rippleEnable, true);

ta.recycle();
}

Expand Down Expand Up @@ -274,7 +274,7 @@ public void setBgSelector() {
}
}

if (view instanceof TextView) {
if (view instanceof TextView || view instanceof EditText) {
TextView textView = (TextView) view;
if (textPressedColor != Integer.MAX_VALUE) {
textColor = (textColor == Integer.MAX_VALUE ? textView.getTextColors().getDefaultColor() : textColor);
Expand Down
21 changes: 21 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@
<attr name="rv_rippleEnable"/>
</declare-styleable>

<declare-styleable name="RadiusEditText">
<attr name="rv_backgroundColor"/>
<attr name="rv_backgroundPressedColor"/>
<attr name="rv_backgroundEnabledColor"/>
<attr name="rv_radius"/>
<attr name="rv_strokeWidth"/>
<attr name="rv_strokeColor"/>
<attr name="rv_strokePressedColor"/>
<attr name="rv_strokeEnabledColor"/>
<attr name="rv_textColor"/>
<attr name="rv_textPressedColor"/>
<attr name="rv_textEnabledColor"/>
<attr name="rv_radiusHalfHeightEnable"/>
<attr name="rv_widthHeightEqualEnable"/>
<attr name="rv_topLeftRadius"/>
<attr name="rv_topRightRadius"/>
<attr name="rv_bottomLeftRadius"/>
<attr name="rv_bottomRightRadius"/>
<attr name="rv_rippleEnable"/>
</declare-styleable>

<declare-styleable name="RadiusLinearLayout">
<attr name="rv_backgroundColor"/>
<attr name="rv_backgroundPressedColor"/>
Expand Down
Binary file modified screenshot/00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshot/01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 89c1756

Please # to comment.