9

アクティビティの上にあるタイトルを削除したい。私はこの2つの方法を試しましたが、APIレベル8では試していません.

1:

<style name="NOtitleTheme" parent="Theme.AppCompat.Light">
<item name="android:windowFullscreen">true</item>
   <item name="android:windowNoTitle">true</item> </style>

2:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

なぜこれがうまくいかないのapi 8ですか?

でなんとか削除できましたがapi 8、方法を覚えていません。


編集:

解決しました!問題は this.requestWindowFeature(Window.FEATURE_NO_TITLE)API 8では<item name="android:windowNoTitle">true</item>機能せず、機能しませんが actionBar.hide()機能します.getSupportActionBar()がnullを返す理由は、以前は2つのオプションのいずれかを使用していたため、両方を削除するのを忘れていました. 1つを削除すると、他のものを追加します(なんてばかです!)ありがとうございます!(下手な英語でごめんなさい)

4

5 に答える 5

3
    <resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->

         <item name="android:windowFullscreen">true</item> <!-- Hides the status bar -->
    </style>

</resources> 

スタイル xml にこれを AppTheme に追加します。

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
    }

}

これをアクティビティに追加します。Activity の代わりに ActionBarActivity を使用します。

于 2014-08-04T13:07:21.773 に答える
1

私にとってうまくいった唯一の方法は、これを行うことでした:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

私のテーマは NoActionBar の子であると言うだけで、actionBar を削除することができました。他のすべての方法は失敗しました。理由がわからない。

于 2017-11-15T23:12:21.363 に答える
0
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

setContentView メソッドの前に requestWindowFeature メソッドを使用します。

于 2014-08-04T12:50:46.823 に答える
0

あなたの「回避策」(アクションバーを自分で隠す)は通常の方法です。ただし、Google では、タイトル バーが非表示の場合は常にアクション バーを非表示にすることをお勧めしています。こちらをご覧ください: https://developer.android.com/training/system-ui/status.html

ビルド バージョンが 16 未満の場合は、以下のように使用します。

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // If the Android version is lower than Jellybean, use this call to hide
    // the status bar.
    if (Build.VERSION.SDK_INT < 16) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    setContentView(R.layout.activity_main);
}
...

}

于 2014-08-04T12:53:28.077 に答える