6

グローバル設定画面でデフォルトのフォントサイズを変更したときに何が起こるかを模倣して、Android アプリケーションですべてのテキストを大きくすることは可能ですか? ユーザーが設定画面でフォント サイズを選択し、すべてのテキストを変更して、個々の画面に余分なスタイル タグを配置する必要がないようにしたいと考えています。

これまでのところ、 のフォント サイズを正しく変更するテーマは 3 つありますが、 や要素TextViewのようなものは変更しません。EditTextListView

<style name="AppThemeSmall" parent="AppTheme">
    <item name="android:textViewStyle">@android:style/TextAppearance.Small</item>
    <item name="android:textAppearance">@android:style/TextAppearance.Small</item>
</style>

<style name="AppThemeMedium" parent="AppTheme">
    <item name="android:textViewStyle">@android:style/TextAppearance.Medium</item>
    <item name="android:textAppearance">@android:style/TextAppearance.Medium</item>
</style>

<style name="AppThemeLarge" parent="AppTheme">
    <item name="android:textViewStyle">@android:style/TextAppearance.Large</item>
    <item name="android:textAppearance">@android:style/TextAppearance.Large</item>
</style>
4

2 に答える 2

0

基本的なウィジェットから拡張する独自のカスタム ウィジェットを作成します。初期化中に、共有設定からフォント設定を取得します。設定が変更されたときに、そこに保存すると思います。初期化中、ウィジェットのテキストサイズは保存された設定に設定されます。コード内:

public class MyCustomTextView extends TextView {

    public MyCustomTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }   

    public MyCustomTextView(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {

        float size = .... // retrieve from your shared preferences
        setTextSize(size);
    }
}

このようにして、textsize 属性を持つすべてのウィジェットを拡張し、初期化中に変更することができます。

于 2013-04-11T13:39:22.210 に答える