Some key points for modifying the style of Android apps _java

Source: Internet
Author: User

You can customize themes and styles in Android. style, which means style, we can take some unified attributes, such as long, wide, font size, font color, and so on. You can create a new Styles.xml file in the Res/values directory, in which there are resource root nodes, add item items in the root node, the name of the item is the name of the attribute, the value of item is the value of the attribute, as follows:

<?xml version= "1.0" encoding= "Utf-8"?> <resources> <style name= "MyText" parent= "
 @android: Style/textappearance ">
   <item name=" Android:textcolor "> #987456 </item>
 <item name=" Android:textsize ">24sp</item>
 </style>
</resources>

There is a parent class attribute in style that indicates that the current style is inherited from that style, and of course the property value of this style contains the attribute, and you can also modify the value of the inherited property, OK, style is complete, We can test the effect, first write a layout file, such as a textview or something, you can use this style. I'll write a edittext here. The following is a layout file:

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
 "http://schemas.android.com/" Apk/res/android "
 android:layout_width=" match_parent "
 android:layout_height=" match_parent ">

< EditText
 android:id= "@+id/myedittext"
 android:layout_width= "Match_parent"
 Match_parent "
 style=" @style/mytext "
 android:text=" test the next "/>
</LinearLayout>

said the style, the following said Theme,theme and style similar, but theme is applied in application or activity inside, and style is applied in a view inside, or there is a difference, well, nonsense not much to say, Let's just look at the code. The following is a style file:

<?xml version= "1.0" encoding= "Utf-8"?> <resources> <style name= "MyText" parent= "
 @android: Style/textappearance ">
 <item name=" Android:textcolor "> #987456 </item>
 <item name=" Android:textsize ">24sp</item>
 </style>
 <style parent=" @android: Style/theme "Name=" Customtheme ">
 <item name=" Android:windownotitle ">true</item>
 <item name=" Android: Windowframe "> @drawable/icon</item>
 <item name=" Android:windowbackground ">?android: windowframe</item>
</style>
</resources>

You can see here that you've written a theme that inherits from the default theme of the system, there are 3 attributes, here to highlight the value of the third attribute problem, here is a question mark, and then add the first item name refers to the name of the value, that is, the corresponding name of the picture.

Then we add a theme attribute to the application inside the manifest.xml, which corresponds to the theme we wrote above.

<application android:icon= "@drawable/icon" android:label= "@string/app_name"
 android:theme= "@style Customtheme ">
<activity android:name=". Teststyle "
 android:label=" @string/app_name ">
<intent-filter>
 <action android:name=" Android.intent.action.MAIN "/>
 <category android:name= android.intent.category.LAUNCHER"/>
 < /intent-filter>
</activity>

The above code has no title bar, background and Fram are all the pictures we set. Of course, you can also set a theme in your code:

Package Com.test.shang;
Import android.app.Activity;
Import Android.os.Bundle;
public class Teststyle extends activity {
 @Override
 protected void onCreate (Bundle savedinstancestate) {
 super.oncreate (savedinstancestate);
 Settheme (r.style.customtheme);
 Setcontentview (R.layout.test_style);
 }

Related Article

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.