Created
January 24, 2020 10:12
-
-
Save HaniehNikjoo/99f85bb73e092bb38e058a9337569450 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.TextView; | |
@SuppressLint("AppCompatCustomView") | |
public class AutoSIzeTextView extends TextView { | |
Context ctx; | |
public AutoSIzeTextView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
ctx = context; | |
init(); | |
} | |
public AutoSIzeTextView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
ctx = context; | |
init(); | |
} | |
public AutoSIzeTextView(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