简体   繁体   English

如何解决Android Studio中的隐藏标题栏问题?

[英]How to resolve hide title bar issue in android studio.?

Am learning android and working on project as well.I just created an android project in android studio and tried to hide the title bar. 我正在学习android并从事项目工作。我刚刚在android studio中创建了一个android项目并试图隐藏标题栏。 more over i have tried all solutions has been using now.but its not working. 而且我尝试了所有解决方案现在都在使用now。但是它不起作用。

I have tried the following sites what they would have done solution for this issue. 我已经尝试了以下网站,他们将如何解决此问题。

http://stackoverflow.com/questions/28080250/android-feature-no-title-not-working
http://stackoverflow.com/questions/9737112/requestwindowfeaturewindow-feature-no-title-causing-the-app-to-crash
http://stackoverflow.com/questions/21354365/android-requestwindowfeaturewindow-feature-no-title-exception
http://stackoverflow.com/questions/27891030/requestwindowfeaturewindow-feature-no-title-error
http://stackoverflow.com/questions/25164171/requestwindowfeaturewindow-feature-no-title-not-working-in-froyo-and-gingerbr
http://stackoverflow.com/questions/25119013/can-not-remove-title-bar-in-activity#

And here is my android manifest file 这是我的android清单文件

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

MainActivity.java MainActivity.java

 public class MainActivity extends AppCompatActivity {

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

styles.xml styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

activity_main.xml activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.raju.androidpractice.MainActivity">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
</RelativeLayout>

I know this very very basic question but whenever i search regarding this issue there is no proper answer and explanation 我知道这个非常基本的问题,但是每当我搜索此问题时,都没有正确的答案和解释

Would appreciate expected solution with brief about this issue.Thanks in advance 对于此问题的简要介绍,我们将不胜感激。提前感谢

Replace your code 替换您的代码
Change extends ActionBarActivity to AppCompatActivity 更改将ActionBarActivity扩展到AppCompatActivity

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

To

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

Change theme name android:theme="@style/AppTheme " 更改主题名称android:theme =“ @ style / AppTheme

and remove requestWindowFeature(Window.FEATURE_NO_TITLE); 并删除requestWindowFeature(Window.FEATURE_NO_TITLE); code in your activity file 活动文件中的代码

Add the following in the <style> tag in res/values/styles.xml: 在res / values / styles.xml的<style>标记中添加以下内容:

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

So you just want to remove the title of the action bar? 因此,您只想删除操作栏的标题? It's very simple: just set this android:label="@string/app_name" to whatever you want the title or android:label="" if you want no title. 这非常简单:只要将此android:label="@string/app_name"为您想要的标题,或者将android:label=""您不想要标题的名称即可。

If your goal is just to hide the title bar (ToolBar), there is a method for that already. 如果您的目标只是隐藏标题栏(ToolBar),那么已经有一种方法。

Try 尝试

getSupportActionBar().hide();

Inside the onCreate method of your activity 在活动的onCreate方法中

try enabling your Activity to Full mode 尝试将您的活动设置为完全模式

activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Studio。 可点击进度条 - Android Studio. Clickable Progress Bar Gradle无法解决Android Studio中的依赖关系。 那是我的错误 - Gradle fails to resolve dependencies in Android Studio. That Is My Error 如何将数据库驱动程序连接到android studio。? - How to connect Database driver to android studio.? 当数组中的第n个元素更新时,自定义适配器Android Studio中的第0个元素也会更新。 如何解决这个问题 - When nth element in array is updated, 0th element is also updated inside custom adapter Android studio. How to resolve this 如何在Android应用程序中隐藏标题栏 - How can I hide the title bar in an android application 自定义标题栏中的问题(android) - issue in custom title bar (android) android studio中的布局问题。 如何使我的相对布局覆盖整个屏幕,而不会卡在左上方? - Issue with layout in android studio. How do I get my relative layout to cover the entire screen and not stay stuck in the top left? 如何在底部导航栏中删除标题标题 - Android Studio - How to remove Header title in bottom nav bar - Android Studio 隐藏没有动画的android标题栏 - hide android title bar without animations 无法在 Android Studio 中检测 textview 字段。 无法解析文本视图 ID - Unable to Detect textview field in Android Studio. Cannot resolve text view ID
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM