0
我正在開發在Android應用程序中,我使用的是包含圖標儀表盤佈局.Dashboard佈局是所有三個標籤通用(在圖像顯示1),現在我的儀表盤佈局正在下面,如何在儀表板佈局中顯示特定的圖標?
默認情況下,當我登錄我的應用程序時,邀請選項卡將打開爲類似於上面的圖像。在該圖像儀表板佈局有3個圖標(即「下拉菜單,事件,設置」) 但我想更改儀表板上的圖標基於選項卡點擊功能。
例如,
在圖像2中,「邀請標籤」需要顯示「設置圖標」僅除了圖標沒有其他圖標需要顯示當我在「邀請標籤」儀表盤佈局。
同樣在圖像-3中,當我在「事件選項卡」時,我需要在dashboardlayout中顯示「事件&設置」圖標。
在圖像-4,當我在 「羣聊標籤」 我需要顯示 「下拉菜單&設置」 圖標,在儀表盤佈局。
我menu_dashboard代碼如下
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appmunu="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="ringee.app.com.ringeeapp.UserDashBoard">
<item
android:id="@+id/dropdown"
android:icon="@drawable/dropdown_icon"
android:title="Dropdown"
appmunu:showAsAction="always">
<menu>
<item
android:id="@+id/all"
android:title="All" />
<item
android:id="@+id/event"
android:title="Event" />
<item
android:id="@+id/invitation"
android:title="Invitation" />
</menu>
</item>
我的儀表盤編碼是下面,
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-4dp"
android:layout_weight="0" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
我 「userdashboard活動」 的編程代碼如下,
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<tabHost.getTabWidget().getChildCount();i++)
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(getResources().getColor(R.color.scandal));//unselected
if(tabHost.getCurrentTab()==0)
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(getResources().getColor(R.color.Orange)); //1st tab selected
else if(tabHost.getCurrentTab()==1)
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(getResources().getColor(R.color.Orange)); //2nd tab selected
else if(tabHost.getCurrentTab()==2)
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(getResources().getColor(R.color.Orange)); //3rd tab selected
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
// noinspection SimplifiableIfStatement
if (id == R.id.account_settings) {
Intent userSettingIntent = new Intent(getApplicationContext(),ActivityUserSettings.class);
userSettingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(userSettingIntent);
return true;
}
if (id == R.id.profile) {
Intent profileIntent = new Intent(getApplicationContext(),ImageUploadActivity.class);
profileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(profileIntent);
return true;
}
if(id == R.id.create_occasion){
Intent occasionAct = new Intent(getApplicationContext(), OccasionActivity.class);
// Clears History of Activity
occasionAct.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(occasionAct);
}
return super.onOptionsItemSelected(item);
}
}
如何解決這個問題問題請幫助我。
好吧,讓我試試 –