System font size settings

Source: Internet
Author: User


Problem:

The font size needs to be modified in the project. When you modify the font size, you can determine whether the current application needs to synchronize the font size of the system. This is generally required for applications that require complete font display. Huawei Glory's mobile phone desktop seems to have made a judgment on this. No matter what the system font is, it seems to be a default value. Anyway, I didn't see any changes with the naked eye. Although it is a bit fixed, it turns into a complete display of the Application name.


Analysis:

Since this function is available in the settings, let's look at his code. The setting interface uses Settings_headers.xml for the xml, which is generally difficult to find. It is better for new users to know this name. Find the writeFontSizePreference function of DisplaySettings. java. This function is responsible for the system font changes after the font changes. The function code is as follows:

public void writeFontSizePreference(Object objValue) {        try {            mCurConfig.fontScale = Float.parseFloat(objValue.toString());            ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig);        } catch (RemoteException e) {            Log.w(TAG, "Unable to save font size");        }    }

You can see that it is set through ActivityManagerNative (note that this is an hide class ). If you are using your own app, you can obtain it through reflection and set the font size. Your app needs to declare the permission android. permission. CHANGE_CONFIGURATION and WRITE_SETTINGS permissions in Manifest. add the android: configChanges = "fontScale" code to xml, and declare the login userid as the System UID. Refer to this article.

However, in our application, we obviously need to know how to notify the app of the system's font modification, to mask or modify the default font size in the system notification, and select the font size suitable for our application. The above function will eventually call the function code: mRemote. transact (UPDATE_PERSISTENT_CONFIGURATION_TRANSACTION, data, reply, 0 );. Through the Binder method, inter-process communication is performed to notify the system that something has changed and update quickly. There is an article about the language update mechanism. For more information, see.

When an update is available, the onConfigurationChanged function of the Activity is triggered for processing. So you can simply reload the function for processing. Of course, in AndroidManifest. xml, the android: configChanges = "fontScale" attribute must be set for this Activity. Because I need to monitor the fontScale, the value is assigned to fontScale.


Solution:

Directly reload the onConfigurationChanged of the target Activity as follows:

    public void onConfigurationChanged(Configuration newConfig) {// TODO Auto-generated method stubLog.i(TAG, "onConfigurationChanged newConfig.fontScale = " + newConfig.fontScale);if(newConfig.fontScale > 1.15f){    newConfig.fontScale = 1.15f;}super.onConfigurationChanged(newConfig);Log.i(TAG, "onConfigurationChanged after");}

If it is greater than a value, set it to 1.15. Because the font size set by the system is small, normal, large, and super large, these parameters are: package/apps/Settings/res/values/arrays. xml

    
         
  
   0.85
          
  
   1.0
          
  
   1.15
          
  
   1.30
      
 

After modification, the compilation is valid.


Method 2:


There is also a way to directly modify the layout of the icon text on the desktop. Reference source file:

Packages \ apps \ Launcher2 \ src \ com \ android \ launcher2 \ PagedViewCellLayout. java can be found in the Code:

mOriginalCellHeight = mCellHeight =            resources.getDimensionPixelSize(R.dimen.apps_customize_cell_height);

Directly modify packages/apps/Launcher2/res/values/dimens. xml:

 
  95dp
 

Modify it to the appropriate value. This method is faster.





























Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.