Android 如何从应用程序UI中删除标题名称和应用程序图标?

Android 如何从应用程序UI中删除标题名称和应用程序图标?,android,android-titlebar,Android,Android Titlebar,我想使用我自己的标题。我想安装应用程序时,应用程序图标和应用程序名称会自动出现。我制作了自己的自定义图像,我想将其用作标题。我使用了以下代码,但它对我无效 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(save

我想使用我自己的标题。我想安装应用程序时,应用程序图标和应用程序名称会自动出现。我制作了自己的自定义图像,我想将其用作标题。我使用了以下代码,但它对我无效

public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState)
{
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
     setContentView(R.layout.homescreen);
     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);


}
}

titlebar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/titlebar"
    android:orientation="horizontal" >
     <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />


</LinearLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/header_text"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center_vertical"
        android:gravity="center"
        android:singleLine="true"
        android:text=""
        android:background="@drawable/titlebar"
        android:textSize="7pt"
        android:textStyle="bold"
        android:typeface="sans" />

     <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />


</LinearLayout>


public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState)
{
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
     //this.requestWindowFeature(Window.FEATURE_NO_TITLE);

     setContentView(R.layout.homescreen);

     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
    // getActionBar().setTitle(R.string.);

}

在活动中使用下面的代码删除默认标题

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_name);
}

在您的xml中,使用具有textview和ImageView的linearlayout创建您自己的自定义标题,这非常容易实现


您也可以从清单文件中更改它

<application
        android:name="com.example.MAPit.Volley.app.AppController"
        android:allowBackup="true"
        android:icon="@drawable/mapit"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
并将值设置为任意值

在XML中:

<activity android:name=".MyActivity" 
       android:icon="@drawable/my_icon" 
       android:label="My new title" />  

代码应该全部放在onCreate中,这样标签/图标的更改对用户来说是透明的,但实际上它可以在活动生命周期的任何地方调用

requestWindowFeature(窗口。功能\u无\u标题)


如果您想使用一些按钮或功能性小部件自定义工具栏或标题,那么可以自定义操作栏,并使用支持操作栏来降低api级别

您也可以从清单文件更改它

<application
        android:name="com.example.MAPit.Volley.app.AppController"
        android:allowBackup="true"
        android:icon="@drawable/mapit"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
更改res/values/string.xml文件中的appname。因此,应用程序的标题将发生变化

现在将图标放在drawable文件夹中,您希望将其用于应用程序和

转到AndroidManifest.xml->选择应用程序->您可以从这里更改图标:从可绘制的图标字段中选择您的图标


在setContentView之前使用此字符串:

requestWindowFeature(Window.FEATURE_NO_TITLE);

您可以使用jyomin答案,或者我从stackoverflow上找到的不同答案中尝试

titlebar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/titlebar"
    android:orientation="horizontal" >
     <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />


</LinearLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/header_text"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center_vertical"
        android:gravity="center"
        android:singleLine="true"
        android:text=""
        android:background="@drawable/titlebar"
        android:textSize="7pt"
        android:textStyle="bold"
        android:typeface="sans" />

     <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />


</LinearLayout>


public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState)
{
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
     //this.requestWindowFeature(Window.FEATURE_NO_TITLE);

     setContentView(R.layout.homescreen);

     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
    // getActionBar().setTitle(R.string.);

}
像这样

<activity android:name="com.bar.start.MainActivity"
              android:label="@string/app_name"
               android:screenOrientation="portrait"
                android:theme="@android:style/Theme">


所以我试过了,现在appicon和appname都不见了。我想使用titlebar.xml作为我的标题,这样就可以使用自定义的标题栏图像。那么我可以使用xml作为我的标题栏吗??(或)是否有必要在需要设置标题栏图像的位置添加textview和imageview。?是的,您可以按照以下步骤进行操作