2017-02-01 6 views
-1

私はAndroid Studio v2.2.3で新しいプロジェクトを作成しました。これは、APIレベル15をターゲットとしたプロジェクトで、開始するブランクアクティビティが1つあります。ここでアンドロイドプロジェクトはアクティビティのメニューを設定します

その活動のための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:id="@+id/activity_starting" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.bfsog.apps.testapp.StartingActivity"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Lorem ipsum"/> 

</RelativeLayout> 

と、私はこれを実行すると、画面の上部に私のアプリの名前を持つ青色のバーがあるし、それを下回っています私のテキストビュー。

私は、同じ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:id="@+id/activity_display_notification" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.bfsog.apps.testapp.SecondActivity"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="ipsum lorem"/> 

</RelativeLayout> 

は今第二の活動のプレビューペインには、上部に水平の青いバーを持っていません。

これはどこに指定されていますか?

編集:私のマニフェスト:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.bfsog.apps.testapp"> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".StartingActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".SecondActivity" 
     android:theme="@style/AppTheme"> 

    </activity> 
</application> 
</manifest> 

最初の活動は、テーマを指定していないが、それは青いバーを取得します。 2番目のアクティビティはテーマを指定しますが、表示されません。

+1

アクションバー、何が必要ですか?それを削除しようとしていますか? – OBX

+0

ツール:コンテキスト、一般的にそのアクティビティに必要なテーマに種を付ける、マニフェストの2番目のアクティビティに同じテーマを設定する、その他の場合はテーマのようにする必要があります。 – Redman

+0

スタイルをテーマに定義する必要があります。 xml。 –

答えて

0

両方のアクティビティで同じテーマを使用する必要があります。最初のアクティビティから別のアクティビティにテーマをコピーする可能性があります。または、このような新しいテーマを作成してください。その後、ActivityManifest.xml

<activity 
      android:theme="@style/AppTheme" 
      android:name=".SecondAct" > 
+0

私の編集を参照してください、私はマニフェストを含めました – andrewb

0

にあなたのres /値/スタイルでActionBar

と呼ばれる

<style name="AppTheme" parent="AppTheme.Base"/> 

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> //this is the action bar background color 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

カスタムテーマを追加し、それを変更します。

<style name="MyCustomTheme" parent="@android:style/Theme.Holo.Light"> 
     <item name="android:actionBarStyle">@style/MyActionBarTheme</item> 
    </style> 

    <style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar"> 
     <item name="android:background">ANY_HEX_COLOR_CODE</item> 
    </style> 

アクションバー表示する:マニフェストで

:アクティビティにアクションバーを非表示にする

android:theme="@style/MyCustomTheme" 

<activity 
     android:name=".SecondActivity" 
     android:label="@string/app_name" //this is the text showing on action bar 
     android:theme="@style/AppTheme"></activity> //use theme 

を、あなたは別の色でカスタムアクションバーを表示することができます使用:

<activity 
     android:theme="@style/Theme.AppCompat.Light.NoActionBar" 
/> 
+0

さて、上記のマニフェストからわかるように、2番目のアクティビティのテーマを指定していて、まだバーはありません – andrewb

+0

'secondActivity code'も投稿して、' AppcompatActivity' – rafsanahmad007

関連する問題