android实现底部菜单栏
2010-09-12 09:49
302 查看
android程序,许多时候需要菜单栏显示在底部或顶部,但是没有很好的组建供程序员调用,过自定义了一个视图,用来实现底部菜单栏,效果如下图:
实现的主要代码:
Java代码
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
linearLayout = (LinearLayout) findViewById(R.id.home);
linearLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
linearLayout
.setBackgroundResource(R.drawable.tab_two_highlight);
publish.setBackgroundResource(R.drawable.tab_one_normal);
change.setBackgroundResource(R.drawable.tab_one_normal);
more.setBackgroundResource(R.drawable.tab_one_normal);
}
});
linearLayout
.setBackgroundResource(R.drawable.tab_two_highlight);
publish = (LinearLayout) findViewById(R.id.publish);
publish.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
publish.setBackgroundResource(R.drawable.tab_two_highlight);
linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
change.setBackgroundResource(R.drawable.tab_one_normal);
more.setBackgroundResource(R.drawable.tab_one_normal);
}
});
change = (LinearLayout) findViewById(R.id.change);
change.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
change.setBackgroundResource(R.drawable.tab_two_highlight);
linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
publish.setBackgroundResource(R.drawable.tab_one_normal);
more.setBackgroundResource(R.drawable.tab_one_normal);
}
});
more = (LinearLayout) findViewById(R.id.more);
more.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
more.setBackgroundResource(R.drawable.tab_two_highlight);
linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
publish.setBackgroundResource(R.drawable.tab_one_normal);
change.setBackgroundResource(R.drawable.tab_one_normal);
}
});
}
配置文件实现:
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="80px"
android:layout_height="wrap_content" android:id="@+id/home"
android:background="@drawable/tab_one_normal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/home"
android:gravity="center" android:paddingTop="29px"
android:background="@drawable/home" />
</LinearLayout>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/line" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="80px"
android:layout_height="wrap_content" android:background="@drawable/tab_one_normal"
android:id="@+id/publish">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/publish"
android:gravity="center" android:paddingTop="29px"
android:background="@drawable/publish" />
</LinearLayout>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/line" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="80px" android:id="@+id/change"
android:layout_height="wrap_content" android:background="@drawable/tab_one_normal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/change"
android:gravity="center" android:paddingTop="29px"
android:background="@drawable/change" />
</LinearLayout>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/line" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="80px" android:id="@+id/more"
android:layout_height="wrap_content" android:background="@drawable/tab_one_normal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/more"
android:gravity="center" android:paddingTop="29px"
android:background="@drawable/more" />
</LinearLayout>
</LinearLayout>
代码详见:http://easymorse.googlecode.com/svn/trunk/android.bottom/
实现的主要代码:
Java代码
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
linearLayout = (LinearLayout) findViewById(R.id.home);
linearLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
linearLayout
.setBackgroundResource(R.drawable.tab_two_highlight);
publish.setBackgroundResource(R.drawable.tab_one_normal);
change.setBackgroundResource(R.drawable.tab_one_normal);
more.setBackgroundResource(R.drawable.tab_one_normal);
}
});
linearLayout
.setBackgroundResource(R.drawable.tab_two_highlight);
publish = (LinearLayout) findViewById(R.id.publish);
publish.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
publish.setBackgroundResource(R.drawable.tab_two_highlight);
linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
change.setBackgroundResource(R.drawable.tab_one_normal);
more.setBackgroundResource(R.drawable.tab_one_normal);
}
});
change = (LinearLayout) findViewById(R.id.change);
change.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
change.setBackgroundResource(R.drawable.tab_two_highlight);
linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
publish.setBackgroundResource(R.drawable.tab_one_normal);
more.setBackgroundResource(R.drawable.tab_one_normal);
}
});
more = (LinearLayout) findViewById(R.id.more);
more.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
more.setBackgroundResource(R.drawable.tab_two_highlight);
linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
publish.setBackgroundResource(R.drawable.tab_one_normal);
change.setBackgroundResource(R.drawable.tab_one_normal);
}
});
}
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); linearLayout = (LinearLayout) findViewById(R.id.home); linearLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { linearLayout .setBackgroundResource(R.drawable.tab_two_highlight); publish.setBackgroundResource(R.drawable.tab_one_normal); change.setBackgroundResource(R.drawable.tab_one_normal); more.setBackgroundResource(R.drawable.tab_one_normal); } }); linearLayout .setBackgroundResource(R.drawable.tab_two_highlight); publish = (LinearLayout) findViewById(R.id.publish); publish.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { publish.setBackgroundResource(R.drawable.tab_two_highlight); linearLayout.setBackgroundResource(R.drawable.tab_one_normal); change.setBackgroundResource(R.drawable.tab_one_normal); more.setBackgroundResource(R.drawable.tab_one_normal); } }); change = (LinearLayout) findViewById(R.id.change); change.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { change.setBackgroundResource(R.drawable.tab_two_highlight); linearLayout.setBackgroundResource(R.drawable.tab_one_normal); publish.setBackgroundResource(R.drawable.tab_one_normal); more.setBackgroundResource(R.drawable.tab_one_normal); } }); more = (LinearLayout) findViewById(R.id.more); more.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { more.setBackgroundResource(R.drawable.tab_two_highlight); linearLayout.setBackgroundResource(R.drawable.tab_one_normal); publish.setBackgroundResource(R.drawable.tab_one_normal); change.setBackgroundResource(R.drawable.tab_one_normal); } }); }
配置文件实现:
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="80px"
android:layout_height="wrap_content" android:id="@+id/home"
android:background="@drawable/tab_one_normal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/home"
android:gravity="center" android:paddingTop="29px"
android:background="@drawable/home" />
</LinearLayout>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/line" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="80px"
android:layout_height="wrap_content" android:background="@drawable/tab_one_normal"
android:id="@+id/publish">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/publish"
android:gravity="center" android:paddingTop="29px"
android:background="@drawable/publish" />
</LinearLayout>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/line" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="80px" android:id="@+id/change"
android:layout_height="wrap_content" android:background="@drawable/tab_one_normal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/change"
android:gravity="center" android:paddingTop="29px"
android:background="@drawable/change" />
</LinearLayout>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/line" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="80px" android:id="@+id/more"
android:layout_height="wrap_content" android:background="@drawable/tab_one_normal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/more"
android:gravity="center" android:paddingTop="29px"
android:background="@drawable/more" />
</LinearLayout>
</LinearLayout>
代码详见:http://easymorse.googlecode.com/svn/trunk/android.bottom/
相关文章推荐
- android实现底部菜单栏
- 【Android UI设计与开发】第06期:底部菜单栏(一)使用TabActivity实现底部菜单栏
- Android RadioGroup+ViewPager+ActionBar实现仿微信6.0界面(底部滑动菜单栏+导航栏)
- Android仿UC底部菜单栏实现原理与代码
- 【Android UI设计与开发】第08期:底部菜单栏(三)Fragment+FragmentTabHost实现仿新浪微博底部菜单栏
- 【Android UI设计与开发】第06期:底部菜单栏(一)使用TabActivity实现底部菜单栏
- Android中实现底部弹出菜单栏
- Android开发Tabhost+RadioGroup实现底部菜单栏
- 【Android UI】RadioGroup+Fragment实现底部菜单栏
- android底部菜单栏实现原理与代码
- 【Android UI设计与开发】第06期:底部菜单栏(一)使用TabActivity实现底部菜单栏
- android tabhost底部菜单栏实现原理与代码
- android实现底部菜单栏
- Android TabHost +Fragment 实现底部菜单栏 .
- 【Android UI设计与开发】7.底部菜单栏(四)PopupWindow 实现显示仿腾讯新闻底部弹出菜单
- 【Android UI设计与开发】4.底部菜单栏(一)Fragment介绍和简单实现
- github开源组件实现android 底部菜单栏
- android底部菜单栏的实现和百度地图API的使用
- Android 底部菜单栏实现
- android底部菜单栏实现