Accumulation of medium and small knowledge points in Android

Source: Internet
Author: User

In Android, how do I set the focus on a specified view:
View. requestfocus ();

Large scroll bar settings:
Listview. setfastscrollenabled (true );

The edittext cursor is on the right, and the input content is from right to left:
Android: gravity = "center_vertical | right"
Or
Edittext. Set
Gravity (gravity. Right );

After edittext settext (), the cursor automatically runs before the first character. You can set the cursor manually:
Edittext. setselection (position); // position indicates the cursor position. It is set to the length of Characters in the edittext input box, And the cursor is the last
To obtain the current cursor position in edittext:
Edittext. getselectionstart ();

Retrieve the Status Bar Height
Decorview is the top-level view in the window. You can obtain the decorview from the window. Then, decorview has a getwindowvisibledisplayfThe rame method can obtain the display area of the program, including the title bar, but not the status bar.
So we can calculate the height of the status bar.
  Rectframe = new rect ();   
  Getwindow (). getdecorview (). getwindowvisibledisplayfRame (FRAME );
  Intstatusbarheight = frame. Top;
Obtain the title bar height:
The getwindow (). findviewbyid (Windows. id_android_content) method obtains the view that the program does not include the title bar, and then you can know the height of the title bar.
 Intcontenttop = getwindow (). findviewbyid (Windows. id_android_content). gettop (); 
 // Statusbarheight is the height of the status bar requested above 
 Inttitlebarheight = contenttop-statusbarheight;

// Hide the keyboard
 (Inputmethodmanager) getsystemservice (input_method_service). hidesoftinputfromwindow (youractivity.This. getcurrentfocus (). getwindowtoken (), inputmethodmanager. hide_not_always );
// Display the soft keyboard. The control ID can be edittext or textview.   (Inputmethodmanager) getsystemservice (input_method_service). showsoftinput (Control ID, 0 );

 

Alertdialog. Bulder of the two buttons:

Newalertdialog. Builder (this). setmessage ("delete this item ")
       . Setpositivebutton ("OK", new dialoginterface. onclicklistener (){ 
           Public void onclick (dialoginterface dialog, int which ){
          Deleteinfo (ID );
          }
    })
    . Setnegativebutton ("cancel", new dialoginterface. onclicklistener (){
             Publicvoid onclick (dialoginterface dialog, int which ){
   }
    }). Show ();

 

Set whether the edittext has a cursor:

Android: cursorvisible = "false"// If it is false, no cursor is selected.

Or edittext. setcursorvisible (visible );

 

View
···
GetlocalvisiblerectReturns a filled rect object, which is the rect size of the view. The left and top values are all 0.
···
GetglobalvisiblerectObtains a view area of the global coordinate system and returns a filled rect object. This rect is based on the overall Screen
···
GetlocationonscreenCalculate the x and y values of the view in the global coordinate system. (Note that the value is counted from the top of the screen, that is, the height of the notification bar is included) // obtain the absolute coordinates on the current screen
···
GetlocationinwindowCalculates the X and Y coordinates of the view in its widnow.

···
Getleft,Gettop,Getbottom,Getright,This group is used to obtain coordinates relative to its father.

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.