Действительно ли возможно заставить GCC читать из канала?

К сожалению, вам придется использовать отражение, чтобы справиться с этим.

Плавающая метка рисуется CollapsingTextHelper, который является внутренним, закрытым для пакета классом и не настроен для обработки промежутков. Таким образом, использование чего-то вроде обычного TypefaceSpan в этом случае не сработает.

Поскольку для этого используется рефлексия, это не гарантированно сработает в будущем.

Реализация

final Typeface tf = Typeface.createFromAsset(getAssets(), "your_custom_font.ttf");
final TextInputLayout til = (TextInputLayout) findViewById(R.id.yourTextInputLayout);
til.getEditText().setTypeface(tf);
try {
    // Retrieve the CollapsingTextHelper Field
    final Field cthf = til.getClass().getDeclaredField("mCollapsingTextHelper");
    cthf.setAccessible(true);

    // Retrieve an instance of CollapsingTextHelper and its TextPaint
    final Object cth = cthf.get(til);
    final Field tpf = cth.getClass().getDeclaredField("mTextPaint");
    tpf.setAccessible(true);

    // Apply your Typeface to the CollapsingTextHelper TextPaint
    ((TextPaint) tpf.get(cth)).setTypeface(tf);
} catch (Exception ignored) {
    // Nothing to do
}

Просмотр ошибок

Если вам нужно изменить шрифт ошибки, вы можете сделать один из двух вещи:

  1. Используйте Reflection, возьмите ошибку TextView и примените Typeface так же, как раньше
  2. Используйте пользовательский диапазон. В отличие от плавающей метки, представление ошибок, используемое TextInputLayout, является просто TextView, поэтому оно может обрабатывать интервалы.

Использование отражения

final Field errorField = til.getClass().getDeclaredField("mErrorView");
errorField.setAccessible(true);
((TextView) errorField.get(til)).setTypeface(tf);

Использование пользовательского диапазона

final SpannableString ss = new SpannableString("Error");
ss.setSpan(new FontSpan(tf), 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
til.setError(ss);

private static final class FontSpan extends MetricAffectingSpan {

    private final Typeface mNewFont;

    private FontSpan(Typeface newFont) {
        mNewFont = newFont;
    }

    @Override
    public void updateDrawState(TextPaint ds) {
        ds.setTypeface(mNewFont);
    }

    @Override
    public void updateMeasureState(TextPaint paint) {
        paint.setTypeface(mNewFont);
    }

}

Результаты

results

Я использую шрифт Smoothie Shoppe .

61
задан Peter Mortensen 22 August 2019 в 12:05
поделиться

2 ответа

Yes, but you have to specify the language using the -x option:

# Specify input file as stdin, language as C
flex -t lexer.l | gcc -o lexer.o -xc -
74
ответ дан 24 November 2019 в 17:20
поделиться
flex -t lexer.l | gcc -x c -c -o lexer.o -

Basically you say that the filename is -. Specifying that a filename is - is a somewhat standard convention for saying 'standard input'. You also want the -c flag so you're not doing linking. And when GCC reads from standard input, you have to tell it what language this is with -x . -x c says it's C code.

18
ответ дан 24 November 2019 в 17:20
поделиться
Другие вопросы по тегам:

Похожие вопросы: