当前位置:首页 > 嵌入式 > 嵌入式软件
[导读] 利用Actionbar同样可以很轻松的实现下拉式的导航方式,相比与tab的方式下拉式的导航方式更类型于html中的标签。若想实现这种效果:1)actionBar.setNavigationMode(ActionB

 

利用Actionbar同样可以很轻松的实现下拉式的导航方式,相比与tab的方式下拉式的导航方式更类型于html中的

01 package ccom.app.main;
02  
03 import android.annotation.SuppressLint;
04 import android.app.Fragment;
05 import android.content.Context;
06 import android.os.Bundle;
07 import android.view.LayoutInflater;
08 import android.view.View;
09 import android.view.ViewGroup;
10 import android.view.ViewGroup.LayoutParams;
11 import android.widget.TextView;
12  
13 @SuppressLint("NewApi")
14 public class MyFragment extends Fragment {
15  
16     @Override
17     public View onCreateView(LayoutInflater inflater, ViewGroup container,
18             Bundle savedInstanceState) {
19  
20         Context context = this.getActivity();
21  
22         TextView tv = new TextView(context);
23  
24         Bundle arc = this.getArguments();
25  
26         int tabs=arc.getInt("key");
27          
28         tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
29                 LayoutParams.WRAP_CONTENT));
30  
31         tv.setText("hello actionbar "+tabs);
32  
33         return tv;
34  
35     }
36  
37 }

main.xml:

01 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
02     xmlns:tools="http://schemas.android.com/tools"
03     android:layout_width="match_parent"
04     android:layout_height="match_parent"
05     tools:context=".Main" >
06  
07     <LinearLayout
08         android:id="@+id/content"
09         android:layout_width="match_parent"
10         android:layout_height="match_parent"
11         android:orientation="vertical" />
12  

 

13 </RelativeLayout>

自定义的用于显示textview的mytextview.xml:

01 <?xml version="1.0" encoding="utf-8"?>
02 <TextView xmlns:android="http://schemas.android.com/apk/res/android"
03     android:id="@+id/text1"
04     android:textColor="#fff"
05     android:background="#696969"
06     android:layout_width="60sp"
07     android:layout_height="match_parent"
08     android:textAppearance="?android:attr/textAppearanceListItemSmall"
09     android:gravity="center_vertical"
10     android:paddingStart="?android:attr/listPreferredItemPaddingStart"
11     android:minHeight="?android:attr/listPreferredItemHeightSmall"
12 />

Main.java

01 package ccom.app.main;
02  
03 import android.annotation.SuppressLint;
04 import android.app.ActionBar;
05 import android.app.Activity;
06 import android.app.FragmentTransaction;
07 import android.os.Bundle;
08 import android.widget.ArrayAdapter;
09  
10 @SuppressLint("NewApi")
11 public class Main extends Activity implements ActionBar.OnNavigationListener {
12  
13     ActionBar actionBar = null;
14  
15     @Override
16     protected void onCreate(Bundle savedInstanceState) {
17         super.onCreate(savedInstanceState);
18         setContentView(R.layout.main);
19  
20         actionBar = this.getActionBar();
21  
22         actionBar.setDisplayShowTitleEnabled(true);
23  
24         actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
25  
26         actionBar.setListNavigationCallbacks(new ArrayAdapter(Main.this,
27                 R.layout.mytextview, R.id.text1, new String[] { "tab1""tab2",
28                         "tab3" }), this);
29  
30     }
31  
32     @Override
33     public boolean onNavigationItemSelected(int itemPosition, long itemId) {
34  
35         MyFragment mf = new MyFragment();
36         Bundle bundle = new Bundle();
37         bundle.putInt("key", itemPosition + 1);
38         mf.setArguments(bundle);
39  
40         FragmentTransaction action = this.getFragmentManager()
41                 .beginTransaction();
42         action.replace(R.id.content, mf);
43         action.commit();
44         return true;
45     }
46  
47 }

实现的效果如图:

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

上海2024年5月20日 /美通社/ -- 2024年5月16日,世界知名的生命科学公司 Eppendorf 集团于第二十三届生物制品年会上成功举办了"疫路超越 推流出新"的产品发布会,正式推出大规模...

关键字: RF PEN BSP IMAC

北京2024年5月20日 /美通社/ -- 过去五年里,支付和收款方式日新月异,其发展和变化比过去五十年都要迅猛。从嵌入式数字商务的出现,到"一拍即付"的...

关键字: VI BSP PAY COM

华钦科技集团(纳斯达克代码: CLPS ,以下简称"华钦科技"或"集团")近日宣布致敬 IBM 大型机 60 载辉煌历程,并将继续实施集团大型机人才培养计划。

关键字: IBM BSP 研发中心 PS

助力科研与检测新突破 上海2024年5月15日 /美通社/ -- 全球知名的科学仪器和服务提供商珀金埃尔默公司今日在上海举办了主题为"创新不止,探索无界"的新品发布会,集中展示了其在分析仪器领域的最...

关键字: 质谱仪 BSP DSC 气相色谱

上海2024年5月16日 /美通社/ -- 2024年5月10日至5月13日,富士胶片(中国)投资有限公司携旗下影像产品创新力作亮相北京P&E 2024。在数码相机展览区域,全新制定的集团使命"为世界绽...

关键字: 富士 数码相机 影像 BSP

贝克曼库尔特目前已成为MeMed Key免疫分析平台和MeMed BV检测技术的授权经销商 在原有合作的基础上,继续开发适用于贝克曼库尔特免疫分析仪的MeMed BV检测 加州布瑞亚和以色列海法2024年5月16日...

关键字: BSP IO 检测技术 免疫分析仪

英国英泰力能的燃料电池是可产业化的产品解决方案 英国首个专为乘用车市场开发的燃料电池系统 在 157kW 功率下,此燃料电池比乘用车的其他发动机更为强大 &...

关键字: ENERGY INTELLIGENT 氢燃料电池 BSP

深爱人才,共赴"芯"程 深圳2024年5月15日 /美通社/ -- 5月11日,深圳国资国企"博士人才荟"半导体与集成电路产业专场活动在深圳市重投天科半导体有限公司(简...

关键字: 半导体 集成电路产业 BSP 人工智能

武汉2024年5月15日 /美通社/ -- 北京时间4月26日-5月4日,2024 VEX 机器人世界锦标赛于美国得克萨斯州达拉斯市举办。本届 VEX 世锦赛为期九天,设有 VIQRC 小学组/初中组、V5RC 初中组/...

关键字: 机器人 BSP RC POWERED

上海2024年5月15日 /美通社/ -- 由生成式人工智能(AI)驱动的临床阶段生物医药科技公司英矽智能宣布,与复星医药(600196.SH;02196.HK)合作开发的潜在"全球首创"候选药物IS...

关键字: ISM BSP PC 人工智能
关闭
关闭