1

使用「設置」按鈕刪除標題欄時出現嚴重問題。 當我嘗試刪除它與代碼:android:theme =「@ android:style/Theme.NoTitleBar.Fullscreen」>或相似我得到應用程序崩潰。無法刪除標題欄Android應用程序

應用程序由啓動屏幕和Web視圖活動組成。

這裏是代碼:

Android清單:

<?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> 
+0

你的LogCat說什麼導致崩潰?發佈堆棧跟蹤(通過LogCat)。 – MarsAtomic 2015-03-25 00:31:14

回答

2

試試這個

變化從程序兼容性主題的基本應用主題到Android主題,創造一個新的主題閃屏。

<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擴展活動,而不是ActionBarActivity

public class MainActivity extends Activity { 

打開menu_main.xml和改變

app:showAsAction="never" 

android:showAsAction="never" 

在AndroidManifest.xml集主題對於閃屏如下

​​

從SplashScreen.java

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

刪除這些行,你會得到你想要的東西。你得到的錯誤是因爲你正在從一個活動切換到ActionBarActivity

+0

工作:D感謝兄弟:D – uncklegwebdev 2015-03-25 10:02:45