Android APP Notes (1) Tips

1. Remove the top title bar

  1. Open res -> values ​​-> styles

  2. Modify DarkActionBar to NoActionBar

Or: add a line of code below the super.oncreat of the activity:

 requestWindowFeature(Window.FEATURE_NO_TITLE);

Note that this method requires that the activity should inherit the activity, not AppCompatActivity, otherwise it will be invalid;

2. Set the transparency of the background

 android:background="#55ffffff"

Just add numbers after #, 00 is fully transparent, ff is opaque

3. Modify the APP icon

The first method: (the easiest way) Put the icon you prepared into the drawable in the res directory, find the two attributes android:icon and android:roundIcon in the AndroidManifest.xml file, and set them to the ones you put in icon file.

imagetext

As shown in the picture, appicon is the file I am going to replace. Note that when saving, save the name without capital letters and spaces, otherwise an error will be reported when compiling. In addition, it is recommended to save the picture format as .png in the found data. However, I have tested .jpg and .png can replace icons correctly.

imagetext

Here, these two attributes can set the icon, and only one can be used to achieve the effect when setting, but if both are used at the same time, the objects specified by the attributes need to be set consistently. If not, the result of my test is the object specified by the displayed roundIcon, and I found the explanation of the android:roundIcon attribute: The android:roundIcon attribute specifies an icon, but you only need to use this attribute when you need to set a special round icon for the application .

The second type: (slightly more complicated) For a more detailed explanation, you can read these two articles: Image Asset Studio, a weapon of Android magic weapon - short book

[Image Asset Studio of Android magic weapon]

The difference between android:icon and android:roundIcon in application

The specific modification method is given here:

imagetext

As shown in the figure, find Image Asset and click. show as below

imagetext

In step 3, select the icon you prepared as the foreground, as shown in the figure:

imagetext

As for the choice of background in step 2, I personally think it can be defaulted. Regarding the content of the foreground and background, there are corresponding instructions in the previous link. If you don’t understand it, you can find out. Then, you can next, finish.

imagetext

imagetext

imagetext

Get the newly created file. Explain here that ic_launcher_round.png is a round icon generated by Image Asset, which can be set in the AndroidManifest file, as in 1. ic_launcher-web.png is used when displaying the app introduction in Google Play.

To sum up, the adaptation effect of the icon generated by method 2 is better, and the effect of method 1 may be different from the pre-conceived effect.

4. Android WebView failed to load

net::ERR_CLEARTEXT_NOT_PERMITTED

First, make sure that the App declares the network permissions

 <uses-permission android:name="android.permission.INTERNET" />

  1. Solution (1):

Turn on a switch in Application

 <manifest ...>
 ​
   <application
 •    android:usesCleartextTraffic="true"
 ​
   </application>
 </manifest>
  1. Solution (2):

Create a new xml directory under res, create a file: network_security_config.xml, the content is as follows:

 <?xml version="1.0" encoding="utf-8"?>
 <network-security-config>
   <base-config cleartextTrafficPermitted="true" />
 </network-security-config>

Add configuration to the application tag of AndroidManifest.xml:

 <manifest ...>
   <application
 •    android:networkSecurityConfig="@xml/network_security_config"
 ​
   </application>
 </manifest>

Solution (3): [Recommended]

Both the server and the local application switch to https

Solution (4):

targetSdkVersion downgrade back to 27

5. Modify the UI in the child thread

Under normal circumstances, an error will be reported when updating the UI in the child thread, because it will be checked by checkThread in ViewRootImpl;

The error must have triggered checkThread, but as long as it is not triggered, the UI can be updated smoothly, and setText will not trigger checkThread under any circumstances.

checkForRelayout is called in the setText method, and this method shows why checkThread will not be triggered. checkThread is only performed in requestLayout, so as long as requestLayout is not called here, checkThread will not be performed.

As long as the size of the View is not wrap_content, but match_parent or fixed dp, requestLayout will not be triggered, and naturally it can be updated in the sub-thread.

6. Solution to the problem of reloading when switching between horizontal and vertical screens in Android development

Solution: In the manifest, set the configChanges of the Activity as:

 android:configChanges="screenSize|keyboardHidden|orientation"

In this way, when the horizontal and vertical screens are switched, the state of the Activity will not change.

Guess you like

Origin blog.csdn.net/aniclever/article/details/120262136