Problem: the keyboard cannot be displayed when you click the input box on the Sina login webpage.
Solution:
MWebView. setOnTouchListener (new View. OnTouchListener (){
@ Override
Public boolean onTouch (View v, MotionEvent event ){
Switch (event. getAction ()){
Case MotionEvent. ACTION_DOWN:
Case MotionEvent. ACTION_UP:
If (! V. hasFocus ()){
V. requestFocus ();
}
Break;
}
Return false;
}
});
The reason is that WeiboDialog of the new Sina interface does not obtain the focus.
Through the isFocusable () method, we can know whether the view is qualified to accept the focus, and set the view acceptance focus qualification through setFocusable;
In touch mode, you can call isFocusableInTouchMode (). you can also use setFocusableInTouchMode (). to set whether there is a focus to respond to the touch.
In the Activity, when we press the top, bottom, left, and right direction keys, the focus in the view will also move. How can we control the moving sequence? In the XML Attribute layout file, there are four attributes: nextFocusDown, nextFocusLeft, nextFocusRight, and nextFocusUp. set their values to define the Id of the next interface to move the focus from the current interface. For example:
<LinearLayout
Android: orientation = "vertical"
...>
<Button android: id = "@ + id/topBtn"
Android: nextFocusUp = "@ + id/bottomBtn" // when the focus is on this topBtn button, press the up arrow key to move the focus to the bottomBtn button.
.../>
<Button android: id = "@ + id/bottomBtn"
Android: nextFocusDown = "@ + id/topBtn" // when the focus is on the bottomBtn button, press the downward arrow key to move the focus to the topBtn button.
.../>
</LinearLayout>
2. Do not let the text input box get the focus by default. The pop-up keyboard occupies our screen
Sometimes, when a page is run on a real machine, the focus is on EditText by default, and the keyboard is automatically displayed to occupy most of the screen. The solution is simple. Add the following statement to the configuration file:
<Activity... android: windowSoftInputMode = "stateAlwaysHidden | adjustResize"/>
By default, the keyboard input method is hidden.
3. When there is a scrollable space nested, for example, if ListView, ScrollView, or EditText is placed in ScrollView, how can we achieve the desired effect? The answer to this question is searching, I hope you can help me with this problem.
OnInterceptTouchEvent () mechanism:
- The down event is first passed to the onintercepttouchevent () method.
- If the onintercepttouchevent () of the viewgroup returns false after the down event is processed, the subsequent move, up, and other events will be passed to the viewgroup first, the ontouchevent () process is passed to the final target view just like the down event.
- If the onintercepttouchevent () of the viewgroup returns true after it receives the down event processing, the subsequent move, up and other events will not be passed to onintercepttouchevent (), the ontouchevent () that is passed to the viewgroup like the down event. Note that the target view will not receive any event.
- If the ontouchevent () of the view that finally needs to process the event returns false, the event will be passed to the ontouchevent () processing of the view at the previous level.
- If the ontouchevent () of the view that finally needs to process the event returns true, the subsequent event can be passed to the ontouchevent () of the view for processing.
1. Set properties. For example, you can set the text content of an instance of the TextView class. Different subclasses can be used to set different attributes and methods. Note: Only attributes that can be detected during compilation can be set in the XML layout management (layout) file. 2. Set the input focus: in response to user input, the entire framework processes the moving focus. To forcibly point the focus to a specific view, you must call the requestFocus () method. 3. Set the listener (listener): In the view, you can set the listener to capture events of interest to the user. For example, you can set listeners to capture all views, whether they get or lose focus. You can register a listener by calling setOnFocusChangeListener (View. OnFocusChangeListener. In other view subclasses, some more special listeners are provided. For example, a Button can trigger an event where the Button is pressed. 4. Set visibility: You can call setVisibility (int) to display or hide a view.
The following uses ImageButton as an example to illustrate how to use setOnFocusChangeListener to implement focus switching.
UI display. when the focus is switched, the content of each ImageButton is displayed on the TextView in the middle.
The Code is as follows:
Public class MainMenu extends Activity {
Private ImageButton btnLogin, btnSet, btnAbout, btnHelp, btnVis;
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. mainmenu );
SetTitle ("Main Menu-Select One Item #");
// Get the buttons, and set listeners.
Btnabout = (imagebutton) findviewbyid (R. Id. ibtnabout );
Btnabout. setonclicklistener (listener );
Btnabout. setonfocuschangelistener (focuslistener );
//...
// Default focus in login button.
Btnlogin. requestfocus ();// Can not work! Y ??? Any one knows this?
// Get the textview to display text.
Tvname = (textview) findviewbyid (R. Id. tvmenu );
Tvname. settext ("");
}
Onclicklistener listener = new onclicklistener (){
Public void onclick (view arg0 ){
Switch (arg0.getid ()){
Case R. Id. ibtnabout:
Tvname. settext ("about ");
Intent in = new intent (mainmenu. This, about. Class );
Startactivity (in );
Break;
//...
}
}
};
Onfocuschangelistener focuslistener = new onfocuschangelistener (){
Public void onfocuschange (view V, Boolean hasfocus ){
If (hasfocus ){
Switch (V. GETID ()){
Case R. Id. ibtnabout:
TvName. setText ("About ");
Break;
//....
}
}
}
};
}
I still don't understand the problem. I hope someone can tell me.When switching to this activity, I want the default focus to be on the button login. I call btnlogin. requestfocus (); doestn't work!
Problem:
After topButton. requestFocus (); is written in the Code, when the program runs, the button does not get the focus.
Solution:
Add when initializing the button
Topbutton.SetFocusable (TrUE); (it is useless to add this one, and the focus cannot be obtained)
Topbutton. setfocusableintouchmode (true); (this must be added. The focus is related to touchmode)