-1

I am making Stopwatch app. I want to change the font size on the landscape mode. So I set up the different font sizes on dimen and dimen-land. Then because of using configChange on AndroidManifest, I added the code to save set up on MainActivity. But it doesn't work that it shows only one font size at the portrait mode and landscape mode. What's wrong with my code?

values/dimen.xml

<resources>
    <dimen name="timerText_fontSize">70sp</dimen>
</resources>

values-land/dimen.xml

<resources>
    <dimen name="timerText_fontSize">150sp</dimen>
</resources>

Layout

<TextView
        android:id="@+id/timerText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="00:00:00"
        android:textSize="@dimen/timerText_fontSize"/>

Main Activity

    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("displayText", timerText.toString());
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState != null) {
            String displayText = savedInstanceState.getString("displayText");
            timerText.setText(displayText);
        }

Manifest

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Design.NoActionBar">

        <activity android:name=".MainActivity"
            android:configChanges="orientation|screenSize|keyboardHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
cloud
  • 77
  • 6

1 Answers1

0

Better to make separate layout for landscape mode.