Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to define the Android title bar utility class

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to define the Android title bar tool class". In the daily operation, I believe that many people have doubts about how to define the Android title bar tool class. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubts of "how to define the Android title bar tool class". Next, please follow the editor to study!

/ * A custom generic title block factual class * / public class CustomeTitleBar extends RelativeLayout {/ * * context * / private Context mContext; / * left text * / private TextView left_tx = null; / * left picture * / private ImageView left_img = null / * left button * / private RelativeLayout left_rl = null; / * middle caption text * / private TextView center_tx = null; / * right universal text * / private TextView right_tx = null; / * right picture * / private ImageView right_img = null / * * right button * / private RelativeLayout right_rl = null; / * title overall layout * / private RelativeLayout title_rl = null; / * * fill the status bar * / private View view_status_bar_place=null; / * * main layout * * / private LinearLayout title_main_view Public LinearLayout getTitle_main_view () {return title_main_view;} public CustomeTitleBar (Context context) {this (context, null);} public CustomeTitleBar (final Context context, AttributeSet attrs) {super (context,attrs); initViews (context,attrs); initListeners ();} / * * initialize the UI component. * / public void initViews (Context context, AttributeSet attrs) {/ / if you use system-dependent code in the constructor of a custom control or other drawing-related places, it will cause the visual editor to fail to report an error and prompt: Use View.isInEditMode () in your custom views to skip code when shownin Eclipse if (isInEditMode ()) {return;} this.mContext=context LayoutInflater.from (this.getContext ()) .propagate (R.layout.include_custometitlebar, this, true); left_tx = (TextView) this.findViewById (R.id.left_tx); left_img = (ImageView) this.findViewById (R.id.left_img); left_rl = (RelativeLayout) this.findViewById (R.id.left_rl) Center_tx = (TextView) this.findViewById (R.id.center_tx); right_tx = (TextView) this.findViewById (R.id.right_tx); right_img = (ImageView) this.findViewById (R.id.right_img); right_rl = (RelativeLayout) this.findViewById (R.id.right_rl); title_rl = (RelativeLayout) this.findViewById (R.id.title_rl) Title_main_view = (LinearLayout) this.findViewById (R.id.title_main_view); view_status_bar_place=this.findViewById (R.id.view_status_bar_place); / / the action button on the right is hidden by default and the text on the left is hidden right_rl.setVisibility (View.GONE); left_tx.setVisibility (View.GONE); initAttrs (attrs) } / * initialize attrs * @ param attrs * / private void initAttrs (AttributeSet attrs) {/ / get the attr attribute TypedArray typedArray = mContext.obtainStyledAttributes (attrs, R.styleable.CustomeTitleBar); / / the icon on the right int rightIcon = typedArray.getResourceId (R.styleable.CustomeTitleBar_rightIcon, 0) / / the middle text int centerTitle = typedArray.getResourceId (R.styleable.CustomeTitleBarenterTextPower0); / / the right text int rightTitle = typedArray.getResourceId (R.styleable.CustomeTitleBarrolled rightText0); if (rightIcontextual 0) {/ / the right icon right_img.setImageResource (rightIcon) } if (central title title 0) {/ / intermediate text center_tx.setText (centerTitle);} if (rightTitletitle title 0) {/ / right text right_tx.setText (rightTitle); right_rl.setVisibility (View.VISIBLE) }} / * backward listening event * / public void initListeners () {left_rl.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {fireBack ();}}) } / * Click the method to be called by the return button * / public void fireBack () {if (this.getContext () instanceof Activity) ((Activity) this.getContext ()) .finish ();} public TextView getLeft_tx () {return left_tx;} public ImageView getLeft_img () {return left_img } public RelativeLayout getLeft_rl () {return left_rl;} public TextView getCenter_tx () {return center_tx;} public TextView getRight_tx () {return right_tx;} public ImageView getRight_img () {return right_img;} public RelativeLayout getRight_rl () {return right_rl } public RelativeLayout getTitle_rl () {return title_rl;} public View getView_status_bar_place () {return view_status_bar_place;}} at this point, the study on "how to define the Android title bar utility class" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report