gpt4 book ai didi

java - 如何让Android Studio中的actionbar消失?

转载 作者:行者123 更新时间:2023-12-02 09:14:56 28 4
gpt4 key购买 nike

我需要让操作栏从屏幕上消失,我已经尝试了在网上找到的所有方法,但似乎没有任何效果。我尝试创建自己的样式,但它不执行任何操作,getActionbar().hide(),它给我一个错误并且无法编译,以及 requestWindowFeature(Window. FEATURE_NO_TITLE);,它也不执行任何操作。我真的需要摆脱那个操作栏。我正在使用传感器景观方向,但我已经尝试更改它,但它没有改变任何内容。

list :

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen>
<activity android:name=".MainActivity" android:screenOrientation="sensorLandscape" android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</activity>
</application>

</manifest>

我自己的风格:

<resources>

<!-- Base application theme. -->

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>

MainActivity.java

package com.example.tanques;

import android.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements JoystickView.JoystickListener, JoystickHorizontal.JoystickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button ShootLeft= findViewById(R.id.ShootLeft);
Button ShootRight= findViewById(R.id.ShootRight);
ShootLeft.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){
Log.d("Button","ShootLeft");
}});
ShootRight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){
Log.d("Button","ShootRight");
}});
}

@Override
public void onJoystickMoved(float Percent, int source) {
switch(source){
case R.id.JoystickLeft:
Log.d("Joystick", "JoystickLeft" + " Percentage: " +Math.round(Percent));
break;
case R.id.JoystickRight:
Log.d("Joystick", "JoystickRight" + " Percentage: " +Math.round(Percent));
break;
case R.id.JoystickTurret:
Log.d("Joystick", "JoystickTurret" + " Percentage: " +Math.round(Percent));
break;
}
}
}

最佳答案

list

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

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

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

</activity>
</application>

</manifest>

样式.xml

<resources>

<!-- Base application theme. -->

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

</resources>

将其放入 MainActivity.java 中的 onCreate() 中,位于 setContentView() 之前

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//add this two lines to your code to hide the system bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN , WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main);

//this hides the navigation bar at the bottom of your device
hideNavigationBar();

final Button ShootLeft= findViewById(R.id.ShootLeft);
Button ShootRight= findViewById(R.id.ShootRight);
ShootLeft.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){
Log.d("Button","ShootLeft");
}});
ShootRight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){
Log.d("Button","ShootRight");
}});
}

创建hideNavigationBar()方法并在onCreate()中调用它

private void hideNavigationBar(){
getWindow().getDecorView()
.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
);
}

关于java - 如何让Android Studio中的actionbar消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59523234/

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