热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在仪表板布局中显示特定图标?-Howtodisplayspecificiconsindashboardlayout?

Iamdevelopinganandroidapplicationinthat,Iamusingdashboardlayoutthatcontainsicons(showe

I am developing an android application in that,I am using dashboard layout that contains icons(showed in image-1).Dashboard layout is common for all the three tabs,Now my dashboard layout is looking below,

我正在开发一个Android应用程序,我正在使用包含图标的仪表板布局(在图像-1中显示)。仪表板布局对于所有三个选项卡都很常见,现在我的仪表板布局如下所示,

enter image description here Bydefaultly ,when i am login my app the invitation tab will opened as similar to above image.In that image dashboard layout have 3 icons(i.e "dropdown,event,settings") But i want to change icon on dashboard based on tab click functionality.

默认情况下,当我登录我的应用程序时,邀请选项卡将打开,类似于上面的图像。在该图像仪表板布局有3个图标(即“下拉列表,事件,设置”)但我想根据选项卡点击功能更改仪表板上的图标。

for example,

In image-2 ,"Invitation tab" need to show "settings icon" only on dashboard layout except that icon no other icon need to display when i am in "invitation tab".

在图像2中,“邀请选项卡”仅需要在仪表板布局上显示“设置图标”,除了该图标当我在“邀请选项卡”中时不需要显示其他图标。

Similarly in image-3, when i am in "event tab" i need to show "event & settings" icons in dashboardlayout.

同样在图像3中,当我在“事件选项卡”中时,我需要在dashboardlayout中显示“事件和设置”图标。

enter image description here

enter image description here

In image-4, when i am in "groupchat tab" i need to show "dropdown & settings" icons in dashboard layout.

在图像4中,当我在“群聊”选项卡中时,我需要在仪表板布局中显示“下拉列表和设置”图标。

My menu_dashboard code is below

我的menu_dashboard代码如下



    
        
            
            
            
        
    

My dashboard coding is below,

我的仪表板编码如下,


    

        

            

            
        

    

My "userdashboard activity" programming code is below,

我的“userdashboard activity”编程代码如下,

package com.ringee.app;



import android.app.ActionBar;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import com.google.gson.Gson;
import com.ringee.app.R;
import com.ringee.app.dataobjects.MessageMO;
import com.ringee.app.utility.AppActivityStatus;
import com.ringee.app.utility.Constants;

import java.util.HashSet;
import java.util.Set;
//new header file is added
import android.widget.TabHost.OnTabChangeListener;

public class UserDashBoardActivity extends ActionBarActivity {

    /** Called when the activity is first created. */
    private static final String TAB_1_TAG = "Invitation";
    private static final String TAB_2_TAG = "Event";
    private static final String TAB_3_TAG = "GroupChat";
    private FragmentTabHost tabHost;
    private Context context;
    private SharedPreferences sharedpreferences;
    private Gson gson = new Gson();

    @Override
    protected void onStart() {
        super.onStart();
        AppActivityStatus.setActivityStarted();
        AppActivityStatus.setActivityContext(context);
    }

    @Override
    protected void onPause() {
        super.onPause();
        AppActivityStatus.setActivityStoped();

    }

    @Override
    protected void onResume() {
        super.onPause();
        AppActivityStatus.setActivityStarted();
    }

    @Override
    protected void onStop() {
        super.onStop();
        AppActivityStatus.setActivityStoped();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_user_dash_board, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_dash_board);
        cOntext= getApplicationContext();
        sharedpreferences = context.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME,
                Context.MODE_PRIVATE);
        // Get TabHost Refference
        tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
        tabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);

        tabHost.addTab(tabHost.newTabSpec(TAB_1_TAG).setIndicator("Invitation"), InvitationFragment.class, null);
        tabHost.addTab(tabHost.newTabSpec(TAB_2_TAG).setIndicator("Event"), OccasionFragment.class, null);
        tabHost.addTab(tabHost.newTabSpec(TAB_3_TAG).setIndicator("GroupChat"), GroupChatFragment.class, null);

        // Set drawable images to tab
        /*tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.ic_action_event);
        tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.ic_action_phone);

        // Set Tab1 as Default tab and change image
        tabHost.getTabWidget().setCurrentTab(0);
        tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.ic_action_person);*/
        //invitation tab highlighted by default
        tabHost.getTabWidget().setCurrentTab(0);
        tabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.Orange));
        tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.scandal));
        tabHost.getTabWidget().getChildAt(2).setBackgroundColor(getResources().getColor(R.color.scandal));


       /* if(getIntent().getExtras() != null && getIntent().getExtras().containsKey("messageMO")) {
            MessageMO messageMO = (MessageMO) getIntent().getExtras().get("messageMO");
            getIntent().getExtras().remove("messageMO");
            Log.i(Constants.TAG, "messageMo object" + messageMO.getMobileNumber());
            SharedPreferences.Editor editor = sharedpreferences.edit();
            editor.putString("messageMo",gson.toJson(messageMO));
            editor.commit();
           tabHost.setCurrentTab(2);
        }*/


        /*tabHost.setOnTabChangedListener(new OnTabChangeListener(){


            @Override
            public void onTabChanged(String tabId) {
                tabHost.getCurrentTabView().setBackgroundColor(getResources().getColor(R.color.scandal));

            }
        });*/
        //onTabChangedListener added for move one tab to others
        tabHost.setOnTabChangedListener(new OnTabChangeListener() {

            @Override
            public void onTabChanged(String arg0) {

                setTabColor(tabHost);
            }
        });


    }
    //setTabColor method added for highlighting the tabs
    public void setTabColor(FragmentTabHost tabHost) {

        for(int i=0;i

How to fix this problem please help me.

如何解决这个问题请帮帮我。

1 个解决方案

#1


0  

Use The ToolBar With Icons in the Activity and when the tab changed Customise your layout

使用工具栏中的“活动中的图标”以及更改选项卡时自定义布局





    

    

and on your Activity something like this

和你的活动这样的东西

myTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (TAB_1_TAG.equals(tabId)) {
                notification.setVisibility(View.GONE);
                searchView.setVisibility(View.VISIBLE);

            }
            if (TAB_2_TAG.equals(tabId)) {
                notification.setVisibility(View.VISIBLE);
                searchView.setVisibility(View.GONE);
            }
        }
    });

推荐阅读
author-avatar
1042613658_047ede
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有