Skip to content

Commit d227231

Browse files
committed
Changed Font,Added new Method setFont() to change Default font
1 parent 3054357 commit d227231

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

app/src/main/java/net/cryptobrewery/syntaxviewexample/MainActivity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected void onCreate(Bundle savedInstanceState) {
2222
//this will set the color of strings between " "
2323
syntax_view.setPrintStatmentsColor("#6a8759");
2424
//this will set the default code text color other than programming keywords!
25-
syntax_view.setCodeTextColor("#000000");
25+
syntax_view.setCodeTextColor("#ffffff");
2626
//this will set programming keywords color like String,int,for,etc...
2727
syntax_view.setKeywordsColor("#cc7832");
2828
//this will set the numbers color in code | ex: return 0; 0 will be colored
@@ -35,6 +35,10 @@ protected void onCreate(Bundle savedInstanceState) {
3535
syntax_view.setAnnotationsColor("#1932F3");
3636
//this will set special characters color like ;
3737
syntax_view.setSpecialCharsColor("#cc7832");
38+
//you can change the font
39+
//code:
40+
// Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "yourFont.ttf");
41+
//syntax_view.setFont(tf);
3842

3943
//on text change listener
4044
syntax_view.code.addTextChangedListener(new TextWatcher() {
@@ -44,7 +48,7 @@ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
4448

4549
@Override
4650
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
47-
//on text change listener
51+
//listen for live changes
4852
Log.d("tester",charSequence.toString());
4953

5054
}
94.7 KB
Binary file not shown.

syntax-view/src/main/java/net/cryptobrewery/syntaxview/SyntaxView.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
import android.app.AlertDialog;
55
import android.content.Context;
66
import android.graphics.Color;
7+
import android.graphics.Typeface;
78
import android.text.Editable;
9+
import android.text.InputType;
810
import android.text.Spanned;
911
import android.text.TextUtils;
1012
import android.text.TextWatcher;
1113
import android.text.style.CharacterStyle;
1214
import android.text.style.ForegroundColorSpan;
1315
import android.util.AttributeSet;
1416
import android.util.Log;
17+
import android.view.inputmethod.EditorInfo;
1518
import android.widget.EditText;
1619
import android.widget.RelativeLayout;
1720
import android.widget.ScrollView;
@@ -69,6 +72,7 @@ public SyntaxView(Context context,String BackgroundColor,String keywordsColor,St
6972

7073
private void initialize(Context context, String BackgroundColor, final String keywordsColor, final String NumberColor, final String specialCharColors, final String printStatmentsColor){
7174
// default/constructor color are set here
75+
7276
setKeywordsColor(keywordsColor);
7377
setNumbersColor(NumberColor);
7478
setSpecialCharsColor(specialCharColors);
@@ -77,9 +81,12 @@ private void initialize(Context context, String BackgroundColor, final String ke
7781
inflate(context, R.layout.syntaxview, this);
7882
code = findViewById(R.id.code);
7983
rows = findViewById(R.id.rows);
80-
code.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
84+
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "progfont.ttf");
85+
code.setTypeface(tf);
86+
code.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
8187
code.setSingleLine(false);
82-
code.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION); code.setBackgroundColor(Color.parseColor(BackgroundColor));
88+
code.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
89+
code.setBackgroundColor(Color.parseColor(BackgroundColor));
8390
code.addTextChangedListener(new TextWatcher() {
8491

8592

@@ -271,6 +278,8 @@ public void setRowNumbersBgColor (String color) throws Error{
271278
rows.setBackgroundColor(Color.parseColor(color));
272279
}
273280

274-
281+
public void setFont(Typeface tf){
282+
code.setTypeface(tf);
283+
}
275284

276285
}

syntax-view/src/main/res/layout/syntaxview.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
android:textColorHighlight="#fff"
4646
android:textColorHint="#fff"
4747
android:textColorLink="#fff"
48-
android:textSize="16sp"
48+
android:textSize="18sp"
4949
app:met_hideUnderline="true"
5050
app:met_textColor="#fff" />
5151

0 commit comments

Comments
 (0)