当前位置: 首页 > news >正文

建设银行贷款网站/徐州百度seo排名

建设银行贷款网站,徐州百度seo排名,网站如何更换图片,java怎莫做web网站标签组件Tabhost类似于Windows应用中的选项框。 TabHost的实现有两种方式,第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost。各个Tab中的内容在布局文件中定义就行了。 第二种方式,不继承TabActivity,在布局…

  标签组件Tabhost类似于Windows应用中的选项框。

   TabHost的实现有两种方式,第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost。各个Tab中的内容在布局文件中定义就行了。

  第二种方式,不继承TabActivity,在布局文件中定义TabHost即可,但是TabWidget的id必须是@android:id/tabs,FrameLayout的id必须是@android:id/tabcontent。

 

一、继承TabActivity

  第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost。各个Tab中的内容在布局文件中定义就行了。

  1、布局文件

  打开“res/layout/activity_main.xml”文件。

  输入以下代码:

<?xml version="1.0" encoding="utf-8"?>  
<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"  
android:orientation="vertical" 
android:layout_width="match_parent"  
android:layout_height="match_parent">  
<LinearLayout android:id="@+id/txtnews" 
android:layout_width="match_parent"  
android:layout_height="match_parent" 
android:gravity="center_horizontal"  
android:orientation="vertical">  
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>  
<LinearLayout 
android:id="@+id/photonews" 
android:layout_width="match_parent"  
android:layout_height="match_parent" 
android:gravity="center_horizontal"  
android:orientation="vertical">  
<AnalogClock android:id="@+id/clock"  
android:layout_width="wrap_content" 
android:layout_height="wrap_content" />  
</LinearLayout>
<LinearLayout android:id="@+id/videonews" 
android:layout_width="match_parent"  
android:layout_height="match_parent" 
android:gravity="center_horizontal"  
android:orientation="vertical">
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ToggleButton" />
</LinearLayout>  
</FrameLayout>  


  2、程序文件 

  打开“src/com.genwoxue.switchtogglebutton/MainActivity.java”文件。

  然后输入以下代码:

package com.genwoxue.tabhost;
import android.app.TabActivity;   
import android.os.Bundle;   
import android.view.LayoutInflater;   
import android.widget.TabHost;  
public class MainActivity extends TabActivity {
//声明TabHost
private TabHost tabNews;  
@Override  
public void onCreate(Bundle savedInstanceState) {  
super.onCreate(savedInstanceState); 
//获得当前MainActivity(继承自TabActivity)的TabHost
tabNews = this.getTabHost();  
// 通俗的说,inflate就相当于将一个xml中定义的布局找出来 
LayoutInflater.from(this).inflate(R.layout.activity_main,tabNews.getTabContentView(), true);  
//添加一个文本新闻选项框
tabNews.addTab(tabNews  
.newTabSpec("firsttab")  
.setIndicator("文本新闻",getResources().getDrawable(R.drawable.ic_launcher))  
.setContent(R.id.txtnews));
//添加一个图片新闻选项框
tabNews.addTab(tabNews  
.newTabSpec("secondtab")  
.setIndicator("图片新闻",getResources().getDrawable(R.drawable.ic_launcher))  
.setContent(R.id.photonews));  
//添加一个视频新闻选项框
tabNews.addTab(tabNews  
.newTabSpec("thirdtab")  
.setIndicator("视频新闻",getResources().getDrawable(R.drawable.ic_launcher))  
.setContent(R.id.videonews));  
}  
}


  3、运行结果

     

 

 

 二、布局文件中定义TabHost

   第二种方式,不继承TabActivity,在布局文件中定义TabHost即可,但是TabWidget的id必须是@android:id/tabs,FrameLayout的id必须是@android:id/tabcontent。

  1、布局文件

  打开“res/layout/activity_main.xml”文件。

  输入以下代码:

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
android:id="@+id/hometabs"  
android:orientation="vertical"  
android:layout_width="match_parent"    
android:layout_height="match_parent">   
<TabHost android:id="@+id/tabhost"  
android:layout_width="fill_parent"  
android:layout_height="wrap_content">  
<LinearLayout  
android:orientation="vertical"  
android:layout_width="match_parent"  
android:layout_height="match_parent">  
<TabWidget android:id="@android:id/tabs"   
android:orientation="horizontal"  
android:layout_width="match_parent"  
android:layout_height="wrap_content">  
</TabWidget>  
<FrameLayout android:id="@android:id/tabcontent"  
android:layout_width="wrap_content"  
android:layout_height="wrap_content">  
<TextView android:id="@+id/text"  
android:layout_width="match_parent"  
android:layout_height="match_parent" 
android:text="第一个选项框"/>  
<TextView android:id="@+id/photo"  
android:layout_width="match_parent"  
android:layout_height="match_parent" 
android:text="第二个选项框"/>  
<TextView android:id="@+id/video"  
android:layout_width="match_parent"  
android:layout_height="match_parent" 
android:text="第三个选项框"/>  
</FrameLayout>  
</LinearLayout>  
</TabHost>  
</LinearLayout>  


 

 

  2、程序文件 

  打开“src/com.genwoxue.tabhost/MainActivity.java”文件。

  然后输入以下代码:

package com.genwoxue.tabhost_b;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TabHost;
import android.widget.TabWidget;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {  
super.onCreate(savedInstanceState);  
setContentView(R.layout.activity_main);  
//获取TabHost对象
TabHost tabHost = (TabHost) findViewById(R.id.tabhost);  
tabHost.setup();  
//获取TabWidget对象
TabWidget tabWidget = tabHost.getTabWidget();
//添加选项框一
tabHost.addTab(tabHost  
.newTabSpec("tab1")  
.setIndicator("文本新闻",getResources().getDrawable(R.drawable.ic_launcher))  
.setContent(R.id.text));  
//添加选项框二
tabHost.addTab(tabHost  
.newTabSpec("tab2")  
.setIndicator("图片新闻",getResources().getDrawable(R.drawable.ic_launcher))  
.setContent(R.id.photo));  
//添加选项框三
tabHost.addTab(tabHost  
.newTabSpec("tab3")  
.setIndicator("视频新闻",getResources().getDrawable(R.drawable.ic_launcher))  
.setContent(R.id.video));  
}
}


  3、运行结果

      

 

补充说明:

  Android 关于inflate
  
  因此如果你的Activity里如果用到别的layout,比如对话框上的layout,你还要设置对话框上的layout里的组件(像图片ImageView,文字TextView)上的内容,你就必须用inflate()先将对话框上的layout找出来,然后再用这个layout对象去找到它上面的组件,如:
  
  Viewview=View.inflate(this,R.layout.dialog_layout,null);
  
  TextViewdialogTV=(TextView)view.findViewById(R.id.dialog_tv);
  
  dialogTV.setText("abcd");
  
  如果组件R.id.dialog_tv是对话框上的组件,而你直接用this.findViewById(R.id.dialog_tv)肯定会报错.
  
  三种方式可以生成LayoutInflater:
  
  LayoutInflaterinflater=LayoutInflater.from(this);
  
  LayoutInflaterinflater=getLayoutInflater();
  
  LayoutInflaterinflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
  
  然后调用inflate方法将xml布局文件转成View
  
  publicViewinflate(intresource,ViewGrouproot,booleanattachToRoot)
  
  在View类中,也有inflate方法
  
  publicstaticViewinflate(Contextcontext,intresource,ViewGrouproot)

http://www.lbrq.cn/news/1345393.html

相关文章:

  • 网页设计素材景区结束/关键词优化排名用什么软件比较好
  • 学徒网页设计师招聘/中山seo排名
  • 如何做优化网站排alexa优化/com域名注册
  • 做网站的好框架/高级搜索指令
  • 中国空间站简介100字/软文代发平台
  • wordpress国内能用吗/免费seo网站自动推广
  • 织梦做公司网站要钱吗/网络seo是什么意思
  • 企业做网站需要提交的资料表格/网销怎么做
  • 上海官网制作/百度app优化
  • 淘宝代购网站建设/百度指数怎么做
  • 网站导航条用什么做/怎么快速推广自己的产品
  • 互联网门户网站模板/推广运营是什么工作
  • 石龙网站仿做/seo优化方法
  • 建网站的公司南京/山东关键词网络推广
  • 建设单位企业锁登陆网站/站内营销推广方式
  • 广州市财贸建设开发监理网站/广州竞价托管代运营
  • 精灵网站建设/镇江网站建设推广
  • 企业网站seo哪里好/微博营销案例
  • 找人做网站注意/软文推广公司有哪些
  • 建设网站应该注意的地方/西安最新消息今天
  • 想做一个网站怎么做/网络营销的发展现状及趋势
  • 佛山响应式网站设计/抖音营销推广怎么做
  • 官网网站建设需求/企业营销型网站
  • 泗县做网站/seo推广什么意思
  • 网站数据库怎么做同步/竞价托管推广
  • 网站建设 问卷调查/保定seo排名外包
  • 龙岗网站设计市场/片多多可以免费看电视剧吗
  • 左中右三栏布局网站建设/百度seo怎么提高排名
  • 什么是网站版式/seo双标题软件
  • table做网站的好处/广州番禺发布网
  • 【精彩回顾·成都】成都 User Group×柴火创客空间:开源硬件驱动 AI 与云的创新实践!
  • Python(6) -- 数据容器
  • FreeRTOS源码分析五:资源访问控制(一)
  • 神经网络-local minima and saddle point
  • ComfyUI——舒服地让大模型为我所用
  • 【性能测试】---测试工具篇(jmeter)