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

时间:2015-03-19 05:24:47

标签: android android-titlebar

remove app icon and tile

我想使用自己的标题。我认为应用程序图标和应用程序名称会在安装应用程序时自动出现。我已经制作了自己的自定义图像,我想将其用作标题。我使用了以下代码,但它是不为我工作

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>

6 个答案:

答案 0 :(得分:1)

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

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

并在您的xml中使用具有textview和ImageView

的linearlayout创建自己的自定义标题

答案 1 :(得分:1)

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

更改 res / values / string.xml 文件中的 appname 。因此,您应用的标题会发生变化。

现在将图标放在要用于应用程序的可绘制文件夹中,并

转到 AndroidManifest.xml - &gt;选择应用 - &gt;您可以从此处更改图标:从图标字段

中选择图标从drawable中选择

icon

答案 2 :(得分:0)

这很容易实现

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

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

将app_name放在strings.xmlres/drawable文件夹中的图标。

如果要在代码调用中更改

setTitle("My new title");
getActionBar().setIcon(R.drawable.my_icon);

并将值设置为您想要的任何值。

在XML中:

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

要启用应用中的后退按钮,请使用

 getActionBar().setHomeButtonEnabled(true);
 getActionBar().setDisplayHomeAsUpEnabled(true);

代码应该全部放在你的onCreate中,这样标签/图标的变化对用户来说是透明的,但实际上它可以在活动的生命周期中随处调用

答案 3 :(得分:0)

您可以使用单行隐藏标题栏

requestWindowFeature(Window.FEATURE_NO_TITLE);

如果您想使用某些按钮或功能小部件自定义条形或标题,则自定义操作栏并使用支持操作栏以降低api级别。

答案 4 :(得分:0)

在setContentView:

之前使用此字符串
requestWindowFeature(Window.FEATURE_NO_TITLE);

答案 5 :(得分:0)

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

titlebar.xml

    <?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.);

}

}

并在清单中使用此行,您将使用哪个活动标记

android:theme="@android:style/Theme"
像这样

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