Điều này có thể thực hiện được với TabActivity
.
nhu cầu điều sau đây ...
TabHost
với TabWidget
ở phía dưới
- Selectors cho mỗi
TabSpec
- Layouts cho TabSpec có huy hiệu hay bất kỳ hiệu ứng đặc biệt khác
- Và cuối cùng
TabActivity
nơi đặt máy chủ Activities
và ActivityGoups
Tôi đã tạo một bố cục màn hình khói hơn.
Sau đây là các bước ...
1. Bạn sẽ cần TabWidget
ở phía dưới của TabHost
của bạn thêm trong res của bạn/layout/host.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#777777">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:id="@+id/layTab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="@drawable/your_navigatio_tab_background_drawable"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
/>
</RelativeLayout>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="@id/layTab"/>
</RelativeLayout>
</TabHost>
2.Tiếp theo bạn sẽ yêu cầu selectors
, một cho mỗi TabSpec
của bạn, Dưới đây là trình chọn bản demo: res/drawable/h omeselector.xml
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false" android:drawable="@drawable/home_image_when_not_selected"/>
<item android:state_selected="true" android:drawable="@drawable/home_selected" />
</selector>
3. Ngoài ra, bạn sẽ được yêu cầu bố trí cho TabSpecs rằng có huy hiệu hay bất cứ điều gì bố trí đặc biệt có hiệu lực, đây ví dụ của tôi giỏ TabSpec có huy hiệu vì vậy tôi đã thực hiện bố trí sau đây gọi là: res /layout/cartbottom.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/cartselector"
android:gravity="right"
>
<Button
android:id="@+id/redbtn"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:text="00"
android:paddingBottom="3dp"
android:gravity="right|center_vertical"
android:paddingRight="9dp"
android:textSize="11dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:background="@drawable/red_badge_drawable"
/>
</RelativeLayout>
4. Và cuối cùng là TabActivity
package x.y;
import android.app.TabActivity;
import android.content.Intent;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.Toast;
import android.widget.TabHost.TabSpec;
public class Host extends TabActivity {
public static Button btnRed; // Works as a badge
//Declared static; so it can be accessed from all other Activities
public static TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.host);
tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec homeTabSpec = tabHost.newTabSpec("tid1");
TabSpec signinTabSpec = tabHost.newTabSpec("tid2");
TabSpec cartTabSpec = tabHost.newTabSpec("tid3");
TabSpec moreTabSpec = tabHost.newTabSpec("tid4");
TabSpec searchTabSpec = tabHost.newTabSpec("tid5");
//Make Intents to your Activities or ActivityGroups
Intent intent1 = new Intent(this, Cart.class);
Intent intent2 = new Intent(this, Home.class);
Intent intent3 = new Intent(this, SignIn.class);
Intent intent4 = new Intent(this, Search.class);
Intent intent5 = new Intent(this, More.class);
LayoutInflater layoutInflater = this.getLayoutInflater();
View layout_with_badge = layoutInflater.inflate(R.layout.cartbottom, null);
btnRed = (Button) layout_with_badge.findViewById(R.id.redbtn);
String cnt = String.valueOf("0");// Number on the badge
btnRed.setBackgroundDrawable(getResources().getDrawable(R.drawable.red_badge_image_drawable));
btnRed.setText(cnt);
btnRed.setOnClickListener(new OnClickListener() {
//@Override
public void onClick(View v) {
tabHost.setCurrentTab(2);
}
});
cartTabSpec.setIndicator(layout_with_badge).setContent(intent1);
Drawable d = getResources().getDrawable(R.drawable.homeselector);
ImageView img1 = new ImageView(this);
img1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
img1.setImageDrawable(d);
homeTabSpec.setIndicator(img1).setContent(intent2);
d = getResources().getDrawable(R.drawable.signinselector);
img1 = new ImageView(this);
img1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
img1.setImageDrawable(d);
signinTabSpec.setIndicator(img1).setContent(intent3);
d = getResources().getDrawable(R.drawable.searchselector);
img1 = new ImageView(this);
img1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
img1.setImageDrawable(d);
searchTabSpec.setIndicator(img1).setContent(intent4);
d = getResources().getDrawable(R.drawable.moreselector);
img1 = new ImageView(this);
img1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
img1.setImageDrawable(d);
moreTabSpec.setIndicator(img1).setContent(intent5);
/* Add tabSpec to the TabHost to display. */
tabHost.addTab(homeTabSpec);
tabHost.addTab(signinTabSpec);
tabHost.addTab(cartTabSpec);
tabHost.addTab(searchTabSpec);
tabHost.addTab(moreTabSpec);
}
}
Làm thế nào nó trông ...
Nó chỉ là một TabWidget với nền hình ảnh tùy chỉnh – Blundell
Đây có thể là nhiều khả năng một giao diện tùy chỉnh bằng cách sử dụng RadioGroup và RadioButtons – Rob
nó một cái nhìn tùy chỉnh thêm trên đầu trang của các quan điểm khác – Azlam