How to reduce the size of the program and use of graphic images?
6 minute(s) read | Published on: Aug 18, 2021 Updated on: Dec 14, 2021 |
In Android systems, when designing applications, you may want to use graphic images to beautify them. In this case, graphic images will reduce the loading speed, which is a bug. As a result, we need to do something else to both use graphic images to beautify applications and increase the loading speed, so the use of shape images is recommended. These images do not affect the loading speed, do not reduce the loading speed of the application, and can still have the beauty of graphic images.
When designing applications (in German: Anwendungen entwerfen ) for the Android system, you may want to color the background or use color spectrums in the design of layouts, in which case it is better not to slow down the loading of the application and have no effect on the loading speed. If they do not have applications, it is better to use shape.
1- We create a new project and choose a custom name like Shape-Gsm.
2- Consider the application layer file or activity_main.xml.
3- I add a Button to the application layer from the Palettes section. On this button that I add to the application layer, we will apply changes to the appearance that these changes do not affect the speed of loading applications.
4- Therefore, in the drawable section, we create an xml file.
5- To create it, we must first click on Drawable, then select the Drawable resource file from the new section.
6- Then, a window will open in which we have to choose the file name. In this part myshape
7- Then, we click on myshape to access the contents inside it in xml format.
8- Inside its contents, we will see that there is a selector tag, which we must remove this tag.
9- Instead of that tag, we should finally write shape to create shape tags.
10- The codes listed below should be in the section and shape tag.
11- The contents of the myshape file are as follows:
In the code above, we need to select a rectangle for the button shape or the one we created to be square. In addition to the rectangle, there are other options that we can select to make the button shape into different shapes.
Stroke can be used to change the appearance of the button. However, the higher the value, the more comprehensive the line around the button. In other words, we can change the string around the button by changing the Stroke values.
The corner is also used for the corners of the button to make the corners of the button soft and round or sharp by setting it.
Using the solid tag, we can easily paint the inside of the button.
After making all the desired and appearance changes, we can assign the xml file to the button we created.
12- I open the activity_main.xml file, and in the Text section, we assign a new property called android:
Background to the button we created.
android: background
13- It should be noted that this property that we have created refers to the Shape property inside the drawable folder called myshape.
14- The complete codes that should be included in the Button tag are as follows:
In the Design section of our application layer, we can see the button created.
Therefore, you may want to apply the changes so that by clicking on that button, its appearance will also change and give a beautiful view of the button. By doing this, we will make the button's appearance different when clicking and when not clicking.
To make changes, clicking on it will change its appearance. We must use the selector tag.
15- In the drawable section, we create a new xml file.
16- Then right click on the Drawable folder.
17- Then, we must go to the Drawable resource file in the new section and click on it.
18- A window will open to change its name and select my selector.
19- Select the ok button and close the window.
20- Inside the my selector file selector tag, apply the code entered below.
21- The contents of the myselector file are as follows:
In the code above, in the state_pressd field, please enter the address of the XML file that we want to change when it clicks. The value of trou is for state_pressd, which means pressed mode, which means that the button is pressed or clicked.
The value is actually in the stte_enable field, and in this field, we enter the address of it that we want to make changes to.
We will see a problem with the android code: drawable = "@ drawable / pressed because its color has changed to red. This error is that there is no pressed file in the drawable directory. It should be noted that the press file indicates whether the button is clicked or not and is used to specify whether the button is connected or not.
22- Create an XML file again in the drawable folder, also called pressd.
23- The contents that should be in the pressd.xml section are as follows:
We will see that the code "android: drawable =" @ drawable / enable also has a problem because its color is red. The cause of this problem is the same as the problem above.
24- Create an XML file again in the drawable folder named enable.
25- The contents of the enable.xml file are as follows:
We must give the button the myselector file address for the switch to work well.
26- In the Text section of the activity_main.xml file, we assign a new android property background to the button.
We must give the button the myselector file address for the switch to work well.
27- In the Text section of the activity_main.xml file, we assign a new android property background to the button.
28- We run the program.
29- We will see that the button's appearance is different after clicking.
30- The button's appearance before clicking is to this state, which is assigned a blue color using the SOLID tag. After the button is clicked, the green color is set inside the SOLID tag.
31- It should be noted that the line's color around the button is also red, which exists in both clicks and not clicked, ie, we have not made any change in the color of the line around the button.
About our Android and iOS app development services