【问题标题】:Android Application Name Appears as horizantal tool bar on the top of each activityAndroid 应用程序名称显示为每个活动顶部的水平工具栏
【发布时间】:2016-11-15 11:05:01
【问题描述】:

我在每个活动的顶部都获得了应用程序名称,这是我不想要的。

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="24" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
     <activity
        android:name=".Splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Login"
        android:windowSoftInputMode="stateHidden"
        android:label="@string/app_name" >
    </activity>

在删除 android:label="@string/app_name" 时,我仍然将每个活动上的应用名称作为应用的包名称。

也试过<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>this。

this上尝试了以下所有答案

但仍会在每个活动中获取应用名称。

【问题讨论】:

  • 请查看截图

标签: android android-layout android-activity sdk


【解决方案1】:

创建自己的样式并在 style.xml 中使用。例如

<style name="YourTheme" parent="AppTheme">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionModeOverlay">true</item>
        <item name="actionModeStyle">@style/SpeazieTheme.ActionMode</item>
    </style>

像这样在清单文件中使用它

替换

android:theme="@style/AppTheme" 

android:theme="@style/YourTheme" 

【讨论】:

    【解决方案2】:

    您在 Manifest 中使用自定义样式:

    android:theme="@style/AppTheme"
    

    确保该样式的父级是.NoTitleBar 主题,即:

    <style name="CustomActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
    

    【讨论】:

    • 给出运行时错误\StudentDesk\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.NoActionBar'.
    • 您的Activity 是否扩展AppCompatActivity?如果您想保持与大部分 Android 操作系统版本的兼容性,则应该这样做。
    【解决方案3】:

    或者简单地选择一个现有的隐藏操作栏的 android 主题。 例如:android:theme="@style/Theme.AppCompat.NoActionBar" 您可以通过设置应用程序样式在整个应用程序中进行操作,也可以仅针对选定的活动进行操作。

    希望对您有所帮助。

    【讨论】:

      【解决方案4】:

      如果您不想要任何操作栏,那么您可以更改您的值/样式

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

      【讨论】:

        【解决方案5】:
        public class UserProfile extends Activity {
        
        ImageView profilePic;
        EditText address_up;
        Button update_up, exit_up;
        
        @Override
        protected void onCreate(Bundle abc) {
            super.onCreate(abc);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.userprofile);
        

        在activity类中如果在setcontentview之前输入代码,那么action bar就会消失。requestWindowFeature(Window.FEATURE_NO_TITLE);

        否则也可以创建自定义样式。

        **

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-05-10
          • 1970-01-01
          • 2018-08-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-10-27
          • 2015-05-16
          相关资源
          最近更新 更多