如何显示TitleBar?
How to show TitleBar?
出了点问题,有一次我在 MainActivity 上丢失了 TitleBar。主题应用了带有标记 "NoActionBar" 的 Apptheme。你能帮我return吗? activity_main.xml、AndroidManifest.xml 和 styles.xml 在正文下方。感谢您的帮助。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:collapseColumns="2">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageButton2"
android:layout_weight="1"
android:baselineAlignBottom="false"
android:src="@drawable/webcam"
android:scaleType="centerInside"
android:layout_column="0"
android:onClick="camact" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/imageButton"
android:layout_column="1"
android:layout_weight="1"
android:src="@drawable/glasses"
android:scaleType="centerInside"
android:onClick="slopes"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageButton3"
android:src="@drawable/bed"
android:scaleType="centerInside"
android:layout_weight="1"
android:layout_column="0" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/imageButton4"
android:layout_weight="1"
android:src="@drawable/food"
android:scaleType="centerInside"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageButton5"
android:src="@drawable/card"
android:scaleType="centerInside"
android:layout_weight="1" />
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageButton6"
android:layout_weight="1"
android:scaleType="centerInside"
android:src="@drawable/weather" />
</TableRow>
</TableLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xyz.crazyk0t.bydalsfjallen" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:screenOrientation="portrait" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main2Activity"
android:label="@string/title_activity_main2">
</activity>
<activity android:name=".Main3Activity"
android:label="@string/title_activity_main3">
</activity>
<activity android:name=".Main4Activity"
android:label="@string/title_activity_main4" >
</activity>
<activity android:name=".Main5Activity"
android:label="@string/title_activity_main5">
</activity>
<activity android:name=".Main6Activity"
android:label="@string/title_activity_main6">
</activity>
</application>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorBackground">@android:color/background_dark</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
被
控制
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
找回标题栏-
<item name="windowActionBar">true</item>
<item name="windowNoTitle">false</item>
如果您使用来自 Theme.AppCompat.*
的主题,您的 activity 必须扩展 AppCompatActivity
而不是 Activity
出了点问题,有一次我在 MainActivity 上丢失了 TitleBar。主题应用了带有标记 "NoActionBar" 的 Apptheme。你能帮我return吗? activity_main.xml、AndroidManifest.xml 和 styles.xml 在正文下方。感谢您的帮助。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:collapseColumns="2">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageButton2"
android:layout_weight="1"
android:baselineAlignBottom="false"
android:src="@drawable/webcam"
android:scaleType="centerInside"
android:layout_column="0"
android:onClick="camact" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/imageButton"
android:layout_column="1"
android:layout_weight="1"
android:src="@drawable/glasses"
android:scaleType="centerInside"
android:onClick="slopes"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageButton3"
android:src="@drawable/bed"
android:scaleType="centerInside"
android:layout_weight="1"
android:layout_column="0" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/imageButton4"
android:layout_weight="1"
android:src="@drawable/food"
android:scaleType="centerInside"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageButton5"
android:src="@drawable/card"
android:scaleType="centerInside"
android:layout_weight="1" />
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageButton6"
android:layout_weight="1"
android:scaleType="centerInside"
android:src="@drawable/weather" />
</TableRow>
</TableLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xyz.crazyk0t.bydalsfjallen" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:screenOrientation="portrait" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main2Activity"
android:label="@string/title_activity_main2">
</activity>
<activity android:name=".Main3Activity"
android:label="@string/title_activity_main3">
</activity>
<activity android:name=".Main4Activity"
android:label="@string/title_activity_main4" >
</activity>
<activity android:name=".Main5Activity"
android:label="@string/title_activity_main5">
</activity>
<activity android:name=".Main6Activity"
android:label="@string/title_activity_main6">
</activity>
</application>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorBackground">@android:color/background_dark</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
被
控制<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
找回标题栏-
<item name="windowActionBar">true</item>
<item name="windowNoTitle">false</item>
如果您使用来自 Theme.AppCompat.*
AppCompatActivity
而不是 Activity