Action Bar如何隐藏在这里?

时间:2015-10-11 13:27:07

标签: android

我正在查看MaterialDesignLibrary的演示应用。

manifest中,它使用AppTheme

<application android:allowBackup="true" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">

AppTheme只是Theme.Light

<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="android:Theme.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. -->
    </style>

</resources>

但是,如果我在我的应用程序中使用相同的主题,我会得到一个动作栏,但不是他们的(使用布局渲染器和模拟器)。有谁知道他们如何设法隐藏行动栏?

由于

编辑这是我的代码

<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"
                tools:context=".MainActivity">

    <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="148dp" >

        <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="128dp"
                android:background="#01579b"
                android:paddingBottom="20dp"
                android:paddingLeft="104dp" android:id="@+id/">

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:text="MaterialDesign"
                    android:textColor="#FFF"
                    android:textSize="25dp" />
        </RelativeLayout>

        <View
                android:layout_width="fill_parent"
                android:layout_height="2dp"
                android:layout_marginTop="128dp"
                android:background="#88CECECE" />

        <com.gc.materialdesign.views.ButtonFloatSmall
                android:id="@+id/buttonColorSelector"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="32dp"
                android:layout_marginTop="108dp"
                android:background="#1E88E5"
                materialdesign:iconDrawable="@drawable/icn_select_color" />
    </RelativeLayout>

</RelativeLayout>

MainActivity.java:

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends Activity {

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


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

清单:

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

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

build.grade:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

模块build.grade:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.1'
    }
}
apply plugin: 'com.android.application'

repositories {
    jcenter()
}

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.tagapp.tagapp"
        minSdkVersion 21
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

以下是渲染器在加载演示应用时显示的内容

enter image description here

他们的应用程序的布局渲染器中没有操作栏,但是我的设置就是{ - 1}}。这是我的:

enter image description here

1 个答案:

答案 0 :(得分:0)

似乎在API 21中

 this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

不起作用。

尝试将此添加到AndroidManifest.xml文件

 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

或添加此

 this.getActionBar().hide();
在super.onCreate(savedInstanceState)之后的onCreate方法中

;