13

Quiero implementar la funcionalidad misma que había en iPhoneinsignia en Android TabHost

enter image description here

implementé la costumbre Tabhost mismo que en el iPhone en la barra inferior. Puedo configurar dos íconos para el estado Normal/Seleccionado, pero necesito el ícono dinámico con el número de notificaciones de que aparecen en Imagen.

Gracias

Respuesta

18

Android ViewBadger pueden ser la solución para usted. (Para su información, no he implementado todavía)

Aquí es el complemento que puede tener como salida por esta solución:

enter image description here

+0

fácil de usar ... BadgeViewer es la clase que va a utilizar. también puede copiar en lugar de usarlo como biblioteca. –

+0

@Paresh Mayani He utilizado esta biblioteca de BadgeViewer y estoy enfrentando el problema aquí he publicado una pregunta http://stackoverflow.com/questions/26099124/tabhost-set- the-badge-position-in-tabs-android –

3

Este es un ejemplo de Cómo agregar una tarjeta de identificación en pestaña

chat_tab.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="0dip" 
    android:layout_height="64dip" 
    android:layout_weight="1" 
    android:layout_marginLeft="-3dip" 
    android:layout_marginRight="-3dip" 
    android:orientation="vertical" 
    android:background="@drawable/tab_indicator" > 

    <ImageView 
     android:id="@+id/chat_icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/chat_icon" 
     android:layout_centerHorizontal="true"/> 

    <TextView 
     android:id="@+id/new_notifications" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/chat_icon" 
     android:layout_toRightOf="@+id/chat_icon" 
     android:layout_marginLeft="-8dp" 
     android:layout_marginTop="0dp" 
     android:paddingTop="2dp" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp" 
     android:paddingBottom="2dp" 
     android:textSize="8sp" 
     android:textStyle="bold" 
     android:textColor="@android:color/primary_text_dark" 
     android:background="@drawable/badge" 
     android:visibility="gone"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/chat" 
     style="@android:attr/tabWidgetStyle" 
     android:textColor="@android:color/tab_indicator_text" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true"/> 


</RelativeLayout> 

Ésta es badge.xml (círculo rojo para las notificaciones de fondo), TextView id:new_notifications fondo

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="oval" > 

    <stroke android:width="2dp" android:color="#FFFFFF" /> 

    <corners android:radius="10dp"/> 

    <padding android:left="2dp" /> 

    <solid android:color="#ff2233"/> 

</shape> 

Luego, en el código que simplemente puede hacer

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

View chatTab = inflater.inflate(R.layout.chat_tab, null); 

tvNewNotifications = (TextView) chatTab.findViewById(R.id.new_notifications); 

intent = new Intent().setClass(MainTab.this, Chat.class); 
tabSpec = tabHost 
      .newTabSpec("chat") 
      .setIndicator(chatTab) 
      .setContent(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); 

Como se puede ver a mi disposición relativa tiene un fondo @drawable/tab_indicator la pestaña indicator.xml es el drawable estándar del marco de la pestaña, que obtuve de la SDK, sugiero que también debe obtenerlo de la carpeta de la api en el SDK como también hay que copiar algunas imágenes de las carpetas dibujable, se puede encontrar your_sdk_drive: \ SDK \ plataformas \ android-8

+1

thnks raja babar :) –

Cuestiones relacionadas