【问题标题】:How to block android:textSize如何阻止 android:textSize
【发布时间】:2019-01-29 12:40:41
【问题描述】:

我有一个混合应用程序,如果用户通过移动设置更改字体大小,我的布局会出现一些问题。
所以,我希望字体大小不会随设置而改变。
我进行了很多搜索,并尝试过这样做:
1. 在 res > values > strings.xml

<?xml version='1.0' encoding='utf-8'?>
<resources>
    <string name="app_name">My App</string>
    <string name="launcher_name">@string/app_name</string>
    <string name="activity_name">@string/launcher_name</string>

    <style name="MyTheme" parent="android:Theme">
        <item name="android:textViewStyle">@style/MyTextView</item>
    </style>

    <style name="MyTextView" parent="android:Widget.TextView">
        <item name="android:textSize">22dp</item>
    </style>
</resources>
  1. 在 AndroidManifest.xml 中

    <manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="1.0" package="com.app.myapp" xmlns:android="http://schemas.android.com/apk/res/android">
        <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
            <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/MyTheme" android:windowSoftInputMode="adjustResize">
                <intent-filter android:label="@string/launcher_name">
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
        <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
    </manifest>
    

但这不起作用,我不明白为什么。
我哪里做错了?

【问题讨论】:

  • 样式的东西不属于string.xml它属于styles.xml
  • 这是我必须创建的文件吗?或者它已经存在,我必须修改它?
  • 你能发布你的xml吗
  • 你指的是哪个xml? config.xml?
  • res > values > styles.xml

标签: android hybrid-mobile-app text-size


【解决方案1】:

试试sp

<item name="android:textSize">22sp</item>

来自prevent system font size changing

【讨论】:

  • 是的,我已经尝试过了,但结果相同。所以,它不起作用。
猜你喜欢
  • 2023-03-11
  • 2021-12-11
  • 2018-12-02
  • 1970-01-01
  • 1970-01-01
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多