我不知道为什么我的操作栏标题名称突然消失。但是图标显示在screeen的顶部。但是应用程序名称没有显示在屏幕顶部。
下面我发布了与此相关的代码。
HomeActivity.java:
package com.sit.loco.activity;
public class HomeActivity extends FragmentActivity
implements
VideoListFragment.OnVideoSelectedListener,ActionBar.OnNavigationListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// add channel list array to actionbar spinner
Context context = getActionBar().getThemedContext();
ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.channel_name, R.layout.sherlock_spinner_item);
list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
// remove actionbar title and add spinner to actionbar
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getActionBar().setListNavigationCallbacks(list, this);
// position = getIntent().getExtras().getInt("position");
Log.v("position", position + "");
appData = ((GemsApplication) this.getApplication()).getAppData();
AppPreferences.setAppPreferences(getApplicationContext());
actionabar = getActionBar();
actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// actionabar.setDisplayHomeAsUpEnabled(true);
viewpager = (ViewPager) findViewById(R.id.pager);
fm = getSupportFragmentManager();
/** Defining a listener for pageChange */
ViewPager.SimpleOnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
actionabar.setSelectedNavigationItem(position);
}
};
}
清单:
<application
android:name="com.sit.loco.app.GemsApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.sit.loco.activity.SplashActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<application>
在res / menu / home.xml中:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menuShare"
android:title="@string/share_it"
android:icon="@drawable/ic_action_share"
android:showAsAction="always|withText"/>
<item
android:id="@+id/menuRate"
android:title="@string/rate_it"
android:icon="@drawable/ic_action_good"
android:showAsAction="always|withText"/>
<item
android:id="@+id/menuAbout"
android:title="@string/about"
android:icon="@drawable/ic_action_info"
android:showAsAction="always|withText"/>
</menu>
我不知道如何解决这个问题。任何人都可以帮助我。谢谢。
答案 0 :(得分:1)
你有这一行:
getActionBar().setDisplayShowTitleEnabled(false);
它会从操作栏中删除标题。将其更改为:
getActionBar().setDisplayShowTitleEnabled(true);
或者完全删除它。