[英]Changing the window title bar on an Android Application
I tried to add a differnt layout for my window title bar, but in the same page I already have an action bar, and when I run my application I receive this error: 我试图为窗口标题栏添加不同的布局,但是在同一页面中我已经有一个动作栏,并且在运行应用程序时出现以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.stampp/com.example.stampp.UI.MainActivity}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.stampp / com.example.stampp.UI.MainActivity}:android.util.AndroidRuntimeException:您无法将自定义标题与其他标题功能结合使用
And here is my code: 这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
ActionBar actionBar = getActionBar();
View fragmentContainer = findViewById(R.id.container);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
Tab alleTab = actionBar.newTab();
alleListTabListener = new TabListener<AlleFragment>(this, R.id.container, AlleFragment.class);
alleTab.setText("Alle").setContentDescription("Alle page").setTabListener(alleListTabListener);
actionBar.addTab(alleTab);
Tab favoriteTab = actionBar.newTab();
favoriteListTabListener = new TabListener<FavoriteFragment>(this, R.id.container, FavoriteFragment.class);
favoriteTab.setText("Favorite").setContentDescription("Favorite page").setTabListener(favoriteListTabListener);
actionBar.addTab(favoriteTab);
Tab umbegungTab = actionBar.newTab();
umbegunfListTabListener = new TabListener<UmbegungFragment>(this, R.id.container, UmbegungFragment.class);
umbegungTab.setText("Umbegung").setContentDescription("Umbegung page").setTabListener(umbegunfListTabListener);
actionBar.addTab(umbegungTab);
}
Here is my window_title.xml 这是我的window_title.xml
<?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"
android:gravity="center"
android:background="@color/menu_background">
<TextView
android:id="@+id/windowTitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="25sp"
android:text="@string/shouts"/>
</RelativeLayout>
The error is thrown when I tried to create my action bar. 当我尝试创建操作栏时抛出该错误。 Can someone tell me how can I resolve this problem? 有人可以告诉我如何解决这个问题吗?
UPDATE Manifest.xml 更新 Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.stampp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.stampp.UI.MainActivity"
android:label="@string/shouts"
android:uiOptions="splitActionBarWhenNarrow">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<supports-screens android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
</manifest>
If you have set Window.FEATURE_CUSTOM_TITLE
once, setFeatureInt
can't be called again. 如果您一次设置了Window.FEATURE_CUSTOM_TITLE
,则不能再次调用setFeatureInt
。 A call to it will boil down to a requestFeature() call in the Window implementation, that method tests for FEATURE_CUSTOM_TITLE and throws the Exception if it is set. 对其的调用将简化为Window实现中的requestFeature()调用,该方法将测试FEATURE_CUSTOM_TITLE并抛出Exception(如果已设置)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.