Created
January 24, 2020 10:17
-
-
Save HaniehNikjoo/0e6a997db568022f30e02fa8f264d764 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.autosizeivew; | |
import android.annotation.SuppressLint; | |
import android.content.Context; | |
import android.text.Editable; | |
import android.text.TextWatcher; | |
import android.util.AttributeSet; | |
import android.util.TypedValue; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
@SuppressLint("AppCompatCustomView") | |
public class AutoSIzeEditText extends EditText { | |
Context ctx; | |
public AutoSIzeEditText(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
ctx = context; | |
init(); | |
} | |
public AutoSIzeEditText(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
ctx = context; | |
init(); | |
} | |
public AutoSIzeEditText(Context context) { | |
super(context); | |
ctx = context; | |
init(); | |
} | |
public void init() { | |
setOnTouchListener(null); | |
addTextChangedListener(new TextWatcher() { | |
@Override | |
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
} | |
@Override | |
public void onTextChanged(CharSequence s, int start, int before, int count) { | |
if (getText().toString().length() <= 10) { | |
setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); | |
} else if (getText().toString().length() > 10) { | |
setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); | |
} | |
} | |
@Override | |
public void afterTextChanged(Editable s) { | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment