View the default attribute values of a specific view.
When analyzing the focus and touch event processing code, I found that some attributes have a very important impact on the Code logic, such as clickable and focusable.
These attributes. What are the default values of these attributes? I have the same questions many times at work. I was not
It is clear that the settings are basically set manually in xml. There are still many people like me. Today I will tell you how to quickly view these default values through the Android source code.
For example, the TextView we often use is probably not clickable, that is, the default value of clickable is false. Next, we use
Source code to see if it is like this. First, let's look at the ctor of its two parameters. The Code is as follows:
public TextView(Context context, AttributeSet attrs) { this(context, attrs, com.android.internal.R.attr.textViewStyle); }
The Code shows that the version of the three parameters is actually called, and the 3rd parameters are given to com. android. internal. R. attr. textViewStyle. Next let's go
Take a look at the system's attrs. xml and find the code similar to this:
<!-- Default TextView style. --><attr name="textViewStyle" format="reference" />
The specific values of these attributes are set in the system's themes. xml file. For details, see:
<style name="Theme"><item name="textViewStyle">@android:style/Widget.TextView</item></style><style name="Theme.Holo"><item name="textViewStyle">@android:style/Widget.Holo.TextView</item></style><style name="Theme.Holo.Light"><item name="textViewStyle">@android:style/Widget.Holo.Light.TextView</item></style>
Then let's go to the styles. xml file to see how these styles are set. The Code is as follows:
<style name="Widget.TextView"> <item name="android:textAppearance">?android:attr/textAppearanceSmall</item> <item name="android:textSelectHandleLeft">?android:attr/textSelectHandleLeft</item> <item name="android:textSelectHandleRight">?android:attr/textSelectHandleRight</item> <item name="android:textSelectHandle">?android:attr/textSelectHandle</item> <item name="android:textEditPasteWindowLayout">?android:attr/textEditPasteWindowLayout</item> <item name="android:textEditNoPasteWindowLayout">?android:attr/textEditNoPasteWindowLayout</item> <item name="android:textEditSidePasteWindowLayout">?android:attr/textEditSidePasteWindowLayout</item> <item name="android:textEditSideNoPasteWindowLayout">?android:attr/textEditSideNoPasteWindowLayout</item> <item name="android:textEditSuggestionItemLayout">?android:attr/textEditSuggestionItemLayout</item> <item name="android:textCursorDrawable">?android:attr/textCursorDrawable</item> </style>
These are the default property values of TextView. The unspecified clickable and focusable values are false. In the same way, let's see how the buttons of the TextView subclass are set:
<style name="Widget.Button"> <item name="android:background">@android:drawable/btn_default</item> <item name="android:focusable">true</item> <item name="android:clickable">true</item> <item name="android:textAppearance">?android:attr/textAppearanceSmallInverse</item> <item name="android:textColor">@android:color/primary_text_light</item> <item name="android:gravity">center_vertical|center_horizontal</item> </style>
We can see that the default focusable and clickable values of the Button are true, and other common attributes such as background, textColor, and gravity are also set here.
Finally, let's take a look at the EditText Code as follows:
<style name="Widget.EditText"> <item name="android:focusable">true</item> <item name="android:focusableInTouchMode">true</item> <item name="android:clickable">true</item> <item name="android:background">?android:attr/editTextBackground</item> <item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item> <item name="android:textColor">?android:attr/editTextColor</item> <item name="android:gravity">center_vertical</item> </style>
The focusableInTouchMode of a Button is also set to true by default. This ensures that the EditText can obtain the focus even in touch mode, which can be clearly classified by the user.
Which control is receiving input.
This article is a little trick in the development process. You can easily know the default attribute values of any Android view through the method described here. Last recommended Article
Yuan You's article on getting custom styles & attribute values: http://www.cnblogs.com/angeldevil/p/3479431.html.
When C #'s listView is opened, the first row of attributes or code is selected by default? I know:
Private void Form1_Load (object sender, EventArgs e)
{
ListView1.Focus ();
ListView1.Items [0]. Selected = true;
}
That's all. Easy, huh, huh !~
C # enableViewState
Indicates whether to maintain the view status between page requests. true indicates whether to maintain the view status; otherwise, false indicates that the default value is true.
The official explanation of EnableViewState is hard to understand. The example explains how to create a Web Form and add ListBox, Button, and method.
Program code
<% @ Page Language = "C #" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Script runat = "server">
Void AddItem (object sender, EventArgs e)
{
List. Items. Add (DateTime. Now. Ticks. ToString ());
}
</Script>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> EnableViewState attribute </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: ListBox ID = "list" runat = "server">
<Asp: ListItem Text = "EnableViewState property" Value = "1"> </asp: ListItem>
</Asp: ListBox>
<Asp: Button ID = "btn" runat = "server" Text = "APPEND Item" OnClick = "AddItem"/>
</Div>
</Form>
</Body>
</Html>
When a browser accesses the webpage, the content in the HTML source file is obtained:
<Input type = "hidden" name = "_ VIEWSTATE" id = "_ VIEWSTATE" value = "/wEPDwUKMTIyNTcyODQzNWRkKV9J6dx90HkLpaqCRtS3s4xsNnc ="/>
The reason why the server in ASP. NET also obtains the list Text Value for the property Value and status ratio of each control stored in the hidden box, such as ListBox Text, Value, and Selected
Start lab
Now, when you click the button, the content of the AddItem method ListBox is also increased on the server side. The HTML source file _ VIEWSTATE is also increased. For DateTime, see ASP. NET Time operations.
Lab again
Now we modify the ListBox EnableViewState attribute false.
<Asp: ListBox ID = "list" runat = "server" EnableViewState = "false">
Click a few buttons again. We can see that when we click the button to add items, we can see that only two items are statically specified in ListBox each time. The AddItem method is used to add the items because The ListBox content is not transmitted to the server through _ VIEWSTATE. before the server knows about ListBox, it also dynamically adds content
Note that the AddItem method is executed every time you click the add number. In some articles, the AddItem method is executed only once when EnableViewState = "false" is used. (edit and delete) only newly added (edited or deleted) Content
Summary
EnableViewState specifies whether to send the property value and status of a certain control to the server.
EnableViewState default value true set false reduce data transfer volume when the program logic allows setting false
EnableViewState is used for controls. It is also used for @ Page, @ Control, and @ Master commands. When the EnableViewState and command syntax settings of the Control are used, the value false is used.