這篇文章主要介紹“怎么定義Android標(biāo)題欄工具類”,在日常操作中,相信很多人在怎么定義Android標(biāo)題欄工具類問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”怎么定義Android標(biāo)題欄工具類”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
目前創(chuàng)新互聯(lián)已為數(shù)千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站托管運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、海陽(yáng)網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
/** * 一個(gè)自定義的通用標(biāo)題欄實(shí)列類 */ public class CustomeTitleBar extends RelativeLayout { /** * 上下文 */ private Context mContext; /** * 左邊文字 */ private TextView left_tx = null; /** * 左圖片 */ private ImageView left_img = null; /** * 左邊按鈕 */ private RelativeLayout left_rl = null; /** * 中間標(biāo)題文本 */ private TextView center_tx = null; /** * 右通用文本 */ private TextView right_tx = null; /** * 右圖片 */ private ImageView right_img = null; /** * 右按鈕 */ private RelativeLayout right_rl = null; /** * title整體布局 */ private RelativeLayout title_rl = null; /** * * 填充狀態(tài)欄 */ private View view_status_bar_place=null; /* * 主布局 * */ 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(); } /** * 初始化UI組件. */ public void initViews(Context context, AttributeSet attrs) { //如果在自定義控件的構(gòu)造函數(shù)或者其他繪制相關(guān)地方使用系統(tǒng)依賴的代碼,會(huì)導(dǎo)致可視化編輯器無(wú)法報(bào)錯(cuò)并提示:Use View.isInEditMode() in your custom views to skip code when shownin Eclipse if (isInEditMode()) { return; } this.mContext=context; LayoutInflater.from(this.getContext()).inflate(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); //默認(rèn)右邊的這個(gè)操作按鈕是隱藏的 和左邊的文字是隱藏的 right_rl.setVisibility(View.GONE); left_tx.setVisibility(View.GONE); initAttrs(attrs); } /** * 初始化attrs * @param attrs */ private void initAttrs(AttributeSet attrs) { //獲取attr屬性 TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.CustomeTitleBar); //右邊圖標(biāo) int rightIcon = typedArray.getResourceId(R.styleable.CustomeTitleBar_rightIcon, 0); //中間文字 int centerTitle = typedArray.getResourceId(R.styleable.CustomeTitleBar_centerText,0); //右邊文字 int rightTitle = typedArray.getResourceId(R.styleable.CustomeTitleBar_rightText,0); if(rightIcon!=0){ //右邊圖標(biāo) right_img.setImageResource(rightIcon); } if(centerTitle!=0){ //中間文字 center_tx.setText(centerTitle); } if(rightTitle!=0){ //右邊文字 right_tx.setText(rightTitle); right_rl.setVisibility(View.VISIBLE); } } /** * 后退監(jiān)聽(tīng)事件 */ public void initListeners() { left_rl.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { fireBack(); } }); } /** * 點(diǎn)擊返回按鈕要調(diào)用的方法 */ 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; } }
到此,關(guān)于“怎么定義Android標(biāo)題欄工具類”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
新聞標(biāo)題:怎么定義Android標(biāo)題欄工具類
地址分享:http://muchs.cn/article8/ghspop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、網(wǎng)站排名、網(wǎng)站改版、自適應(yīng)網(wǎng)站、網(wǎng)站營(yíng)銷、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)