无法移除Title Bar Android应用

时间:2015-03-24 22:59:52

标签: java android-activity android-studio android-manifest main-activity

使用“设置”按钮删除标题栏时出现大问题。 当我尝试用代码删除它时:android:theme =" @android:style / Theme.NoTitleBar.Fullscreen">或类似的我得到应用程序崩溃。

应用程序包含Splash屏幕和Web View活动。

这是代码:

Android Manifest:

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:debuggable="false" >
    <!-- Splash screen -->

    <activity
        android:name=".splashscreen"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:noHistory="true" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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


    <!-- Main activity -->
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
    </activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

Splashscreen.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" >

<ImageView
    android:src="@drawable/splash"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="fitXY"/>

</RelativeLayout>

Splashscreen.java

<?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" >

<ImageView
    android:src="@drawable/splash"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="fitXY"/>

</RelativeLayout>

Splashscreen.java

package uniquewebsolutions.slatkimacorcvecara;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;

public class splashscreen extends Activity {

private static int splashInterval = 6000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.splashscreen);

    new Handler().postDelayed(new Runnable() {


        @Override
        public void run() {
            Intent i = new Intent(splashscreen.this, MainActivity.class);
            startActivity(i);
            this.finish();
        }

        private void finish() {
            // TODO Auto-generated method stub
        }
    }, splashInterval);
}}

MainActivity.java

package uniquewebsolutions.slatkimacorcvecara;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;


public class MainActivity extends ActionBarActivity {

private WebView mWebView;

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

    mWebView = (WebView) findViewById(R.id.activity_main_webview);
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebView.loadUrl("http://androidapp.cvecaraslatkimacor.com/");
    // Force links and redirects to open in the WebView instead of in a browser
    mWebView.setWebViewClient(new MyAppWebViewClient());

           mWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

}

@Override
public void onBackPressed() {
    if(mWebView.canGoBack()) {
        mWebView.goBack();
    } else {
        super.onBackPressed();
    }
}


@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);
}
}

ActivityMain.xml

<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">

<WebView
    android:id="@+id/activity_main_webview"
    android:layout_height="match_parent"
    android:layout_width="match_parent" />
</RelativeLayout>

1 个答案:

答案 0 :(得分:2)

试试这个

将基本应用程序主题从Appcompat主题更改为Android主题,并为Splash屏幕创建一个新主题。

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.DeviceDefault.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

<!-- Splash screen theme. -->
<style name="SplashTheme" parent="android:Theme.DeviceDefault.Light.NoActionBar">
    <!-- Customize your theme here. -->
</style>
</resources>

现在让MainActivity扩展Activity而不是ActionBarActivity

public class MainActivity extends Activity {

打开menu_main.xml并更改

app:showAsAction="never"

android:showAsAction="never"

在AndroidManifest.xml中设置Splash Screen的主题如下

<activity
    android:name=".splashscreen"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@style/SplashTheme"
    android:noHistory="true" >

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

从SplashScreen.java中删除这些行

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

你会得到你想要的东西。您得到的错误是因为您正在从Activity切换到ActionBarActivity

相关问题