IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Android probleme avec TabHost


Sujet :

Android

  1. #1
    Membre du Club
    Homme Profil pro
    Debuttant en developpement d'application
    Inscrit en
    Novembre 2014
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Guinée

    Informations professionnelles :
    Activité : Debuttant en developpement d'application

    Informations forums :
    Inscription : Novembre 2014
    Messages : 86
    Points : 55
    Points
    55
    Par défaut Android probleme avec TabHost
    Bonsoir tout le monde,
    J'utilise un TabHost et je veux affiché une icon & un texte, mais le probleme est
    que je n'arrive pas a affiché les deux en meme temps, quand je met le texte l'icon ne s'affiche pas.
    Voici ma fonction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     private void initTabHost() {
            //tabHost = new TabHost(getApplicationContext());
            tabHost = (TabHost)findViewById(android.R.id.tabhost);
            tabHost.setup();
            Drawable d = ContextCompat.getDrawable(this, R.drawable.home);
     
            String[] tabName = {"Tab1", "Tab2", "Tab3", "Tab4", "Tab5", "Tab6"};
           for(int i =0; i<tabName.length; i++)
            {
                TabHost.TabSpec tabSpec;
                tabSpec = tabHost.newTabSpec(tabName[i]);
                tabSpec.setIndicator("", d);
                tabSpec.setContent(new FakeContent(getApplicationContext()));
                tabHost.addTab(tabSpec);
     
            }
            tabHost.setOnTabChangedListener(this);
        }
    S'il vous plait si quelqu'un a une idee.
    Merci d'avance

  2. #2
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2013
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2013
    Messages : 31
    Points : 38
    Points
    38
    Par défaut
    Hello,

    en regardant la doc :
    TabHost.TabSpec setIndicator(View view)
    Specify a view as the tab indicator.

    TabHost.TabSpec setIndicator(CharSequence label, Drawable icon)
    Specify a label and icon as the tab indicator.
    setIndicator peut donc soit prendre une vue personnalisé, ou bien un label et son icon.

    finalement ton code serait donc :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
     private void initTabHost() {
            //tabHost = new TabHost(getApplicationContext());
            tabHost = (TabHost)findViewById(android.R.id.tabhost);
            tabHost.setup();
            Drawable d = ContextCompat.getDrawable(this, R.drawable.home);
     
            String[] tabName = {"Tab1", "Tab2", "Tab3", "Tab4", "Tab5", "Tab6"};
           for(int i =0; i<tabName.length; i++)
            {
                TabHost.TabSpec tabSpec;
                tabSpec = tabHost.newTabSpec();
                tabSpec.setIndicator(tabName[i], d);
                tabSpec.setContent(new FakeContent(getApplicationContext()));
                tabHost.addTab(tabSpec);
     
            }
            tabHost.setOnTabChangedListener(this);
        }

  3. #3
    Membre du Club
    Homme Profil pro
    Debuttant en developpement d'application
    Inscrit en
    Novembre 2014
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Guinée

    Informations professionnelles :
    Activité : Debuttant en developpement d'application

    Informations forums :
    Inscription : Novembre 2014
    Messages : 86
    Points : 55
    Points
    55
    Par défaut
    Merci, bon au fait quand je met le titre comme ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    tabSpec.setIndicator(tabName[i], d);
    seulement le texte s'affiche et quand je retire le texte comme ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    tabSpec.setIndicator("", d);
    l'icon j'affiche. Mon souhait est d'afficher les deux.

  4. #4
    Membre régulier
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2012
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2012
    Messages : 100
    Points : 91
    Points
    91
    Par défaut
    Peux-tu envoyer l'activité et le fichier layout et je veux voir ton problème.
    eriwang2@yahoo.fr

  5. #5
    Membre du Club
    Homme Profil pro
    Debuttant en developpement d'application
    Inscrit en
    Novembre 2014
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Guinée

    Informations professionnelles :
    Activité : Debuttant en developpement d'application

    Informations forums :
    Inscription : Novembre 2014
    Messages : 86
    Points : 55
    Points
    55
    Par défaut
    L’activité
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    package com.gammaconcept.sadgc.sogam.fragments;
     
    import android.content.Context;
    import android.os.Bundle;
    import android.support.annotation.Nullable;
    import android.support.v4.app.Fragment;
    import android.support.v4.view.ViewPager;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.TabHost;
     
    import com.gammaconcept.sadgc.sogam.R;
    import com.gammaconcept.sadgc.sogam.adapters.MyFragmentPagerAdapter;
     
    import java.util.ArrayList;
    import java.util.List;
     
    /**
     * Created by SADGC on 5/30/2016.
     */
    public class Home extends Fragment implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener{
     
        private TabHost tabHost;
        private ViewPager viewPager; View v;
        private MyFragmentPagerAdapter myFragmentPagerAdapter;
     
        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
     
            v = inflater.inflate(R.layout.tabs_viewpager_layout, container, false);
     
            //Init tabhost
            this.initializeTabHost(savedInstanceState);
            //Init view pager
            this.initializeViewPager();
            return v;
        }
     
        private void initializeViewPager() {
     
     
     
            List<Fragment> fragments = new ArrayList<Fragment>();
     
            fragments.add(new Fragment1());
            fragments.add(new Fragment2());
            fragments.add(new Fragment3());
     
            myFragmentPagerAdapter = new MyFragmentPagerAdapter(getFragmentManager(), fragments);
            viewPager = (ViewPager) v.findViewById(R.id.view_pager);
            viewPager.setAdapter(this.myFragmentPagerAdapter);
            viewPager.setOnPageChangeListener(this);
     
        }
     
        private void initializeTabHost(Bundle savedInstanceState) {
            tabHost = (TabHost) v.findViewById(android.R.id.tabhost);
            tabHost.setup();
            for (int i = 1; i <= 3; i++)
            {
                TabHost.TabSpec tabSpec;
                tabSpec = tabHost.newTabSpec("Menu "+i);
                tabSpec.setIndicator("Menu "+i, getResources().getDrawable(R.drawable.ic_home_black_24dp));
                tabSpec.setContent(new FakeContent(getActivity()));
                tabHost.addTab(tabSpec);
            }
            tabHost.setOnTabChangedListener(this);
        }
     
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
     
        }
     
        @Override
        public void onPageSelected(int position) {
     
            this.tabHost.setCurrentTab(position);
        }
     
        @Override
        public void onPageScrollStateChanged(int state) {
     
        }
     
        @Override
        public void onTabChanged(String s) {
     
            int selectedItem = tabHost.getCurrentTab();
            viewPager.setCurrentItem(selectedItem);
        }
     
        public class FakeContent implements TabHost.TabContentFactory
        {
            Context context;
     
            public FakeContent(Context context) {
                this.context = context;
            }
     
            @Override
            public View createTabContent(String s) {
     
                View fakeView = new View(context);
                fakeView.setMinimumHeight(0);
                fakeView.setMinimumWidth(0);
                return fakeView;
            }
        }
    }
    Le fichier Layout
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
     
       <TabHost
            android:id="@android:id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
     
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
     
                <HorizontalScrollView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/h_scroll_view"
                    android:fillViewport="true"
                    android:scrollbars="none">
     
                    <TabWidget
                        android:id="@android:id/tabs"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                    </TabWidget>
     
                </HorizontalScrollView>
     
                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                </TabWidget>
     
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
     
                    <android.support.v4.view.ViewPager
                        android:id="@+id/view_pager"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                    </android.support.v4.view.ViewPager>
     
                </FrameLayout>
     
     
     
           </LinearLayout>
     
        </TabHost>
     
     
    </RelativeLayout>

Discussions similaires

  1. probleme avec android studio2.1
    Par kapac dans le forum Android
    Réponses: 2
    Dernier message: 02/05/2016, 15h52
  2. probleme avec android studio
    Par kapac dans le forum Android Studio
    Réponses: 0
    Dernier message: 24/04/2014, 15h04
  3. Probleme de compillation sur Android Studio avec emulateur
    Par petitdede dans le forum Android Studio
    Réponses: 2
    Dernier message: 15/04/2014, 18h06
  4. Probleme avec ADB Android sur Mac Os X
    Par mrdimeh dans le forum Android
    Réponses: 3
    Dernier message: 01/04/2013, 17h47
  5. probleme avec eclipse sous android
    Par bennour.mohamed dans le forum Android
    Réponses: 5
    Dernier message: 09/03/2011, 14h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo