Android Studio bilan birgalikdagi imtiyozlar Shrift turini belgilang

Hozir menda (Tanlangan, qalin, chizilgan) uslubi bo'lgan List Preference-dan matnni tanlashga harakat qilmoqdaman, lekin men bunga qanday erishish mumkinligiga ishonchim komil emas.

Ilgari, men shrift turiga, o'lchamiga va ranglariga erishganman.

Shrift turi Misol:

         SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String s = sharedPreferences.getString("font_list", "gnuolane rg.ttf");
    Typeface face = Typeface.createFromAsset(getAssets(), "fonts/" + s);
    editText.setTypeface(face);

Shrift o'lchami Misol:

         String s2 = sharedPreferences.getString("font_size", "8");
    editText.setTextSize(Float.parseFloat(s2))

Qanday qilib qalin, kursiv, Underlined kabi shrift turmagi bilan bir xil fikrga erishishim mumkin?

1

6 javoblar

Faqat BOLD va ITALIC uchun savolga javob bera olaman (ayniqsa, EditText ni ta'kidlash mumkin deb o'ylamayman, lekin men noto'g'ri bo'lishi mumkin ):

String fontSize = sharedPreferences.getString("font_size", "8");
String style= sharedPreferences.getInt("font_style", TypeFace.NORMAL);
String font = sharedPreferences.getString("font_list", "gnuolane rg.ttf");
Typeface face = Typeface.create(Typeface.createFromAsset(getAssets(), "fonts/" + s),style);
editText.setTextSize(Float.parseFloat(fontSize ))

Ko'rib turganingizdek, stil editText.getTypeface() orqali o'qilishi mumkin bo'lgan tamsayı ichida tamsayı o'zgaruvchisidir. GetStyle() ( va keyin sharedPreferences ga saqlanadi).

Uslub uchun mumkin bo'lgan qiymatlar:

Typeface.NORMAL
Typeface.BOLD
Typeface.ITALIC
Typeface.BOLD_ITALIC

Lekin, bu ishlashi uchun shriftni yaratgan narsangiz turli shrift uslublarini qo'llab-quvvatlaydi (bu odatda mening ma'lumotim uchun emas).

0
qo'shib qo'ydi

Faqat BOLD va ITALIC uchun savolga javob bera olaman (ayniqsa, EditText ni ta'kidlash mumkin deb o'ylamayman, lekin men noto'g'ri bo'lishi mumkin ):

String fontSize = sharedPreferences.getString("font_size", "8");
String style= sharedPreferences.getInt("font_style", TypeFace.NORMAL);
String font = sharedPreferences.getString("font_list", "gnuolane rg.ttf");
Typeface face = Typeface.create(Typeface.createFromAsset(getAssets(), "fonts/" + s),style);
editText.setTextSize(Float.parseFloat(fontSize ))

Ko'rib turganingizdek, stil editText.getTypeface() orqali o'qilishi mumkin bo'lgan tamsayı ichida tamsayı o'zgaruvchisidir. GetStyle() ( va keyin sharedPreferences ga saqlanadi).

Uslub uchun mumkin bo'lgan qiymatlar:

Typeface.NORMAL
Typeface.BOLD
Typeface.ITALIC
Typeface.BOLD_ITALIC

Lekin, bu ishlashi uchun shriftni yaratgan narsangiz turli shrift uslublarini qo'llab-quvvatlaydi (bu odatda mening ma'lumotim uchun emas).

0
qo'shib qo'ydi

O'ylaymanki, siz buni qila olasiz

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
int font_face = sharedPreferences.getInt("font_face", Typeface.NORMAL);
editText.setTypeface(Integer.toString(font_face));

Odatda Typeface.BOLD , Typeface.BOLD_ITALIC , Typeface.ITALIC , Typeface.NORMAL bu havola .

0
qo'shib qo'ydi
Kechirasiz, endi getString ni getInt ga o'zgartirdim.
qo'shib qo'ydi muallif bismute, manba
ba'zi bir sabablarga ko'ra "Typeface.NORMAL" liniyasi haqida shikoyat qilmoqda
qo'shib qo'ydi muallif EzioBahin, manba

O'ylaymanki, siz buni qila olasiz

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
int font_face = sharedPreferences.getInt("font_face", Typeface.NORMAL);
editText.setTypeface(Integer.toString(font_face));

Odatda Typeface.BOLD , Typeface.BOLD_ITALIC , Typeface.ITALIC , Typeface.NORMAL bu havola .

0
qo'shib qo'ydi
Kechirasiz, endi getString ni getInt ga o'zgartirdim.
qo'shib qo'ydi muallif bismute, manba
ba'zi bir sabablarga ko'ra "Typeface.NORMAL" liniyasi haqida shikoyat qilmoqda
qo'shib qo'ydi muallif EzioBahin, manba

Buni ko'ring.

Shrift turini saqlash

private void storeFontStyle(int style){

        SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        SharedPreferences.Editor editor=sharedPreferences.edit();

        editor.putInt("font_face", style);

        editor.apply();

    }

Shrift turini olish

private int getFontStyle(){

    SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    int font_face = sharedPreferences.getInt("font_face", Typeface.NORMAL);

    return font_face;
}

Shrift turiga kirish

int font_face=getFontStyle();

    editText.setTypeface(null, font_face);
0
qo'shib qo'ydi
Ha, men javobimda o'zgardi
qo'shib qo'ydi muallif ak sacha, manba
Buni tekshirib ko'ryapsizmi?
qo'shib qo'ydi muallif ak sacha, manba
"Typeface.Normal" va "Integer.toString (font_face)" da shikoyat qiladi;
qo'shib qo'ydi muallif EzioBahin, manba
chunki ikkinchi parametr sifatida ulush imtiyozlarini qabul qila olmayman
qo'shib qo'ydi muallif EzioBahin, manba
Ha. va bu ilovaning qulashi
qo'shib qo'ydi muallif EzioBahin, manba

Buni ko'ring.

Shrift turini saqlash

private void storeFontStyle(int style){

        SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        SharedPreferences.Editor editor=sharedPreferences.edit();

        editor.putInt("font_face", style);

        editor.apply();

    }

Shrift turini olish

private int getFontStyle(){

    SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    int font_face = sharedPreferences.getInt("font_face", Typeface.NORMAL);

    return font_face;
}

Shrift turiga kirish

int font_face=getFontStyle();

    editText.setTypeface(null, font_face);
0
qo'shib qo'ydi
Ha, men javobimda o'zgardi
qo'shib qo'ydi muallif ak sacha, manba
Buni tekshirib ko'ryapsizmi?
qo'shib qo'ydi muallif ak sacha, manba
"Typeface.Normal" va "Integer.toString (font_face)" da shikoyat qiladi;
qo'shib qo'ydi muallif EzioBahin, manba
chunki ikkinchi parametr sifatida ulush imtiyozlarini qabul qila olmayman
qo'shib qo'ydi muallif EzioBahin, manba
Ha. va bu ilovaning qulashi
qo'shib qo'ydi muallif EzioBahin, manba