Android UI design summary

Source: Internet
Author: User

Tyle = "margin: 20px 0px; text-align: Left; color: RGB (54,46, 43); line-Height: 26px; font-family: Arial; font-size: 14px ">

Translucent<Buttonandroid: Background = "# e0000000".../>
Transparent<Buttonandroid: Background = "#00000000".../>

Other transparency: InRGBBefore the value (100), Such# 90436eee(RGBIs436eee),# 50436eee, Different display effects are displayed based on the value size. The smaller the value, the higher the transparency.

2. Set the button background image or color:

BTN. setbackgroundresource (R. drawable.Comment_sel);

BTN. settextcolor (getresources (). getcolor (R. color.Blue));

3. Text line feed: & # x000a; (add a semicolon ).

4. During layout, too much Nesting is not recommended; otherwise, Stack Overflow exceptions may be reported.

5.9.png images are best placed in the drawable-hdpi folderOtherwise, black outer lines may appear.

6. Android process priority:Foreground process> visable process (not displayed on the front end, but not completely hidden, such as a pop-up dialog activity)> serviceprocess> background process> Empty Process.

7. Android process startup:Packageservice à packagemanager à load the manifest configuration file-> Read the instances of the main and launcher à ing classes.

8. textview setting symbolsEnter a question mark (such as a question mark) in the English keyboard environment. Otherwise, it is displayed as a ellipsis.

9. append the edittext character:

Edit. append ("0 ");

Edit. gettext (). insert (edit. getselectionstart (), "0 ");

10. edittextRemove the default border:Android: Background = "@ null"OrAndroid: Background = "#00000000


11. WeightUse:The significance of weight is that for parent controls, if the child control can be fully displayed, the control without weight is allocated first. For controls with the weight attribute, the weight valueEqual scoreThe rest of the layout. For example, the left-right layout of relativelayout is used, but the text line breaks in the second layout due to different words. Solution: Set Weight = 1 for the textview in the middle, and use linearlayout for the outer layer or others to achieve the desired effect.

12. When converting a string, String. valueof is preferred.It is best to make a non-null judgment when using tostring directly. For the differences between the two, refer to the source code.

13. If (all) resources cannot be found in the android projectCan be an image question, check if 9.png has a problem.

14. Set the onclick event for the entire linearlayout (or other widgets) control:

(1) set cliclickable = true in. XML (you do not need to set it. The difference is that after setting it to trueCodeRegister a listener event. Otherwise, clickProgramWill Crash), and then rewrite the onclick method directly;

(2) Set onclick = "Name (RESPONSE event name)" in XML, and write a name (view v) method in the activity to execute the clicked operation.

15. The windowleaked of dialog is abnormal:

Alertdialogdialog = new alertdialog. Builder (this );

Dialog. Show ();

Finish ();

The dialog. Show on Android does not block the calling thread (such as the UI thread). As a result, before the dialog is dismiss or cancel, the context on which the dialog depends is disabled, so windowleaked appears. However, this problem does not affect the continued running of the program.

Solution: In the onclicklistener event of dialog, first dismiss (there is a dialoginterface parameter in onclick, you can directly call dismiss of dialoginterface) and then finish the activity (the dismiss () of dialog is called first when the button is clicked () and then call the finish () method of the activity ).

16. When edittext is included in XML, the page is shrunk up when the keyboard is displayed:

Solution: In manifest. android: windowsoftinputmode = "adjustpan" is set for the corresponding activity in XML, and if the XML contains listview, Android: fastscrollenabled = "true" Android: focusable = "true" (to be verified again ).

17. If linearlayout sets the onclicklistener Click EventThe button cannot be placed in the linearlayout. Otherwise, when you click the entire linearlayout, you cannot execute the click command in the area occupied by the button. (Maybe you can solve it by setting focusable)

18. The gettext method of edittext does not return null.(Therefore, gettext is called without mull judgment ).

19. textview:

You can use Android: textstyle = "bold" in the XML file to set English to bold,

However, you cannot set Chinese to bold,

The method to set Chinese to bold is:

Textview TV = (textview) findviewbyid (R. Id. textview01 );

Textpaint TP = TV. getpaint ();

TP. setfakeboldtext (true );

20. timepicker, datepicker: enter a dynamic update date based on the keyboard

When timepicker is used, datepicker cannot be blocked. Therefore, you can enter a date on the keyboard.

Suppose there is a OK button. When you manually enter a date on the keyboard and click "OK", the correct date value cannot be obtained. Solution: Find timepicker in findviewbyid and call requestfocus () in datepicker. Click OK to call clearfocus ().

 

21. Set full screen:

1) Before setcontentview:

Requestwindowfeature (window. feature_no_title );

Getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen, windowmanager. layoutparams. flag_fullscreen );

2) custom style: <style name = "full_screen">

<Itemname = "Android: windownotitle"> true </item>

<Itemname = "Android: windowfullscreen"> Android: windownotitle </item>

</Style>

Set Android: theme = "@ style/full_screen" for the corresponding activity"

3) set Android: theme = "@ Android: style/theme. Black. notitlebar. fullscreen" directly in the activity"

22. Center The View:

With the weight attribute, you can add an empty View to the upper and lower sides or left sides:

<View Android: layout_width = "0dip"

Android: layout_height = "0dp"

Android: layout_weight = "1"

/>

23. When viewflipper is nested in fragment, the sliding touch has no response:

In oncreateview, set view. setontouchlistener (this) for the view obtained by inflate );

Returns true (instead of detector. ontouchevent) when the ontouch method is rewritten )).

24. Set the image to fill it with the imageview control:

To match the width and height attributes of imageview (for example, fill_parent), set scaletype = "fitxy ".

25. If the android signature expiresProject will report an error, unable to package, cannot be compiled.

26. Use intent on the adapter to start the activity:

Input the context parameter in the constructor and start the activity with context. startactivity.

27. View setting padding and margin:

Padding: directly call setpadding ();

Margin: first construct layoutparams Params = newlayoutparams (layoutparams. fill_parent, layoutparams. wrap_content); then Params. setmargins (, 10); finally

View. setlayoutparams (Params );

28. Use of the soft keyboard imeoptions:

Android: imeoptions = "flagnoextractui" // disable full screen display on the keyboard.

At the same time, this property also controls the display content of the buttons in the lower right corner of the soft keyboard, which is the return key by default.

Android: imeoptions = "actionnone" // No prompt is displayed on the right of the input box.

Android: imeoptions = "actiongo" // the content of the button in the lower right corner is 'start'

Android: imeoptions = "actionsearch" // click the button in the lower right corner to search for a magnifier image.

Android: imeoptions = "actionsend" // the content of the buttons in the lower right corner is 'send'

Android: imeoptions = "actionnext" // the content of the buttons in the lower right corner is 'Next'

Android: imeoptions = "actiondone" // The button content in the lower right corner is 'complete'

29. edittext:

XML: Android: maxlength = "15"

Code: edittext. setfilters (newinputfilter [] {New inputfilter. lengthfilter (15 });

30. java. Lang. instantiationexception:Can't instantiate class com. SNS. UI. login $ userlogin; no empty Constructor

The internal userlogin class is declared as static.

31. determine that the current flight mode is used:

Settings. system. getint (context. getcontentresolver (),

Settings. system. airplane_mode_on, 0) = 0;

32.ListenersEnterKey, clickEnterImplement logon or other response events:

Edittext. setoneditexceptionlistener (newoneditexceptionlistener (){

 

@ Override

Publicboolean oneditpartition tion (textview V, int actionid, keyevent event ){

// Todoauto-generated method stub

Server. login (login. This, name, PWD );

Returnfalse;

}

});

33.If the activity is set to full screen, sethasoptionsmenu (true) in fragment will not be able to see the menu item.

34. popupwindow: disappears when an external form is clicked.
Popupwindow. setoutsidetouchable (true );
Popupwindow. setfocusable (true );
Popupwindow. setbackgrounddrawable (New bitmapdrawable (); // important: Click it to disappear without affecting the background.
35.Use spannablestringbuilder to process textview:
Spannablestringbuilder style = new spannablestringbuilder (STR );
Style. setspan (New foregroundcolorspan (color. argb (255, 12,170,218), spannable. span_exclusive_inclusive );
Mtextview. settext (style );
Note: When you set custom color, the color. argb method is preferentially called (using color. RGB may cause errors ).

36. Custom AdapterWhen inherited from baseadapter, viewholder uses a static class. Non-static viewholder will cause the listview to be compared When sliding.
37. java. lang. runtimeexception: unable to destroy activity {COM. demo. ***. maintabactivity}: Java. lang. runtimeexception: unable to destroy activity {COM. demo. ***. tabactivity01}: Java. lang. illegalstateexception: activity has been destroyed
Check the lifecycle of an activity. Do not put irrelevant code on ondestroy.
38. The listview item is used to touch and click a widget.:
Set the corresponding widget in the item layout:
Android: focusable = "false"
Android: focusableintouchmode = "false"
Android: clickable = "false"
This mainly focuses on obtaining the focus priority so that widgets do not obtain the focus by default.
39. There is no border in edittext, and only the bottom border appears in the focus:

Check whether Android: targetsdkversions has been set in manifest. xml. For example, if Android: targetsdkversion = 13 (4.0 platform) is to be tested on the platform 3.2, the edittext border is missing. Delete the Android: targetsdkversion tag.

 

40. For edittext, click the screen to hide the soft keyboard:

Set the ID for layout of the current activity, and then override the onclick method:

Inputmethodmanagerimm = (inputmethodmanager) getsystemservice (context. input_method_service );

Imm. hidesoftinputfromwindow (V. getwindowtoken (), 0 );

 

41. Android. View. windowmanager $ badtokenexception: unable to add window -- tokenandroid. App. localactivitymanager $ localactivityrecord @ 41226b10 is not valid; isyour activity running?

This error occurs when the dialog (alertdialog) is displayed in the activity or view.

1) if the context used to construct the dialog is getapplication, change it to the corresponding activity and add the view to the activity.

2). If tabactivity is used (or tabacitivity is nested in tabactivity), the context uses getparent.

 

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.