[Android] title management, android title
1.1 General title
1.1.1 title content management
1.1.2 help and return buttons
1.2 Unlogged-on title
1.3 title in Login
1.4 title after login
Package com. tsh. lottery. view. manager; import com. tsh. lottery. r; import android. app. activity; import android. view. view; import android. widget. relativeLayout;/*** title management ** @ author taoshihan **/public class TitleManager {private RelativeLayout generalTitle, unloginTitle, loginTitle; private static TitleManager instance = new TitleManager (); private TitleManager () {} public static TitleManager getInstance () {return instance;}/*** initialize the title * @ param activity */public void init (Activity activity) {generalTitle = (RelativeLayout) activity. findViewById (R. id. title_general); loginTitle = (RelativeLayout) activity. findViewById (R. id. title_login); unloginTitle = (RelativeLayout) activity. findViewById (R. id. title_unlogin);}/*** hide all titles */public void hideTitle () {generalTitle. setVisibility (View. GONE); unloginTitle. setVisibility (View. GONE); loginTitle. setVisibility (View. GONE);}/*** display general titles */public void showGeneralTitle () {hideTitle (); generalTitle. setVisibility (View. VISIBLE);}/*** display Unlogged title */public void showUnloginTitle () {hideTitle (); unloginTitle. setVisibility (View. VISIBLE);}/*** display the title of the login */public void showLoginTitle () {hideTitle (); loginTitle. setVisibility (View. VISIBLE );}}
2.1 configuration of configuration text
2.2 create a menu resource file
2.3 set in Activity
Configuration file:
Set Theme under Theme. Holo.
<Application android: theme = "@ android: style/Theme. Holo. Light">
Menu file:
The showAsAction attribute in item must be filled in. For example, always show the meaning, while never does not.
ActionViewClass attribute. You can set the View control. For example, android. widget. SearchView indicates Display Search.
Solve the Problem of invisible buttons in overflow:
This problem occurs when the physical menu key exists. Only press the physical menu key and the hidden button is displayed below.
Use reflection to modify the static sHasPermanentMenuKey variable of the ViewConfiguration class
/*** Add Menu */@ Override public boolean onCreateOptionsMenu (menu Menu) {MenuInflater inflater = getMenuInflater (); inflater. inflate (R. menu. menu, menu); return super. onCreateOptionsMenu (menu);}/*** solve the ActionBar problem */public void setOverflowMenuQues () {ViewConfiguration viewConfiguration = ViewConfiguration. get (this); try {Field field = ViewConfiguration. class. getDeclaredField ("sHasPermanentMenuKey"); field. setAccessible (true); field. setBoolean (viewConfiguration, false);} catch (Exception e) {e. printStackTrace ();}}
<? Xml version = "1.0" encoding = "UTF-8"?> <Menu xmlns: android = "http://schemas.android.com/apk/res/android"> <item android: id = "@ + id/menu_search" android: actionViewClass = "android. widget. searchView "android: showAsAction =" always "android: title =" Search "/> <item android: showAsAction =" always "android: id =" @ + id/menu_user "android: title = "user"/> <item android: showAsAction = "never" android: id = "@ + id/menu_cart" android: title = "shopping"/> <item android: showAsAction = "always" android: id = "@ + id/menu_edit" android: title = "edit"/> <item android: showAsAction = "never" android: id = "@ + id/menu_setting" android: title = ""/> </menu>