或类似的应用程序崩-6ren">
gpt4 book ai didi

java - 无法删除标题栏 Android 应用程序

转载 作者:行者123 更新时间:2023-11-30 03:30:07 25 4
gpt4 key购买 nike

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

应用程序由启动屏幕和 Web View Activity 组成。

代码如下:

Android list :

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

最佳答案

试试这个

将基本应用程序主题从 Appcompat 主题更改为 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 扩展 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

关于java - 无法删除标题栏 Android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29244485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com