작업 표시 줄에서 텍스트를 변경하는 방법 이름 만

현재는 응용 프로그램의 이름 만 표시하고 사용자 정의 무언가를 표시하고 내 응용 프로그램의 각 화면마다 다르게하고 싶습니다.

예를 들어, 내 홈 화면은 작업 표시 줄에 ‘page1’이라고 말하고 앱이 전환하는 다른 활동은 해당 화면 작업 표시 줄에 ‘page2’를 가질 수 있습니다.



답변

업데이트 : 최신 ActionBar (제목) 패턴 :

참고로 ActionBar 는 API 레벨 11에서 도입되었습니다. ActionBar는 활동 제목 , 탐색 모드 및 검색과 같은 기타 대화식 항목을 표시 할 수있는 활동 상단의 창 기능 입니다.

제목 표시 줄을 사용자 정의하고 응용 프로그램을 통해 일관성있게 만드는 것에 대해 정확하게 기억합니다. 따라서 이전과 비교할 수 있으며 ActionBar 사용의 장점을 나열 할 수 있습니다.

  1. 이 시스템은 다양한 화면 구성에 맞게 시스템이 적절하게 조정되는 응용 프로그램에서 친숙한 인터페이스를 사용자에게 제공합니다.
  2. ActionBar는 이미 최상위 추상화가 준비되어 있으므로 개발자는 활동 제목, 아이콘 및 탐색 모드를 표시하기 위해 많은 코드를 작성할 필요가 없습니다.

예를 들면 다음과 같습니다.

=> 정상적인 방법,

getActionBar().setTitle("Hello world App");
getSupportActionBar().setTitle("Hello world App");  // provide compatibility to all the versions

=> 작업 표시 줄 사용자 정의,

예를 들면 다음과 같습니다.

@Override
public void setActionBar(String heading) {
    // TODO Auto-generated method stub

    com.actionbarsherlock.app.ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.title_bar_gray)));
    actionBar.setTitle(heading);
    actionBar.show();

}

작업 표시 줄 스타일링 :

ActionBar는 기본적이고 친숙한 모양, 탐색 모드 및 기타 빠른 작업을 제공합니다. 그러나 이것이 모든 앱에서 동일하게 보이는 것은 아닙니다. UI 및 디자인 요구 사항에 따라 사용자 지정할 수 있습니다. 스타일과 테마를 정의하고 작성하면됩니다.

더 읽기 : 액션 바 스타일링

그리고 ActionBar의 스타일을 생성하려면이 스타일 생성기 도구가 도움이 될 수 있습니다.

===================================================== ================================

이전 : 이전 :

=> 정상적인 방법,

각 화면의 제목 (예 : 활동)을 변경할 수 있습니다. Android:label

   <activity android:name=".Hello_World"
                  android:label="This is the Hello World Application">
   </activity>

=> 사용자 정의-제목-막대


그러나 원하는 방식으로 제목 표시 줄을 사용자 정의 Want to put Image icon and custom-text하려면 다음 코드를 사용하십시오.

main.xml

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

titlebar.xml

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

<ImageView android:id="@+id/ImageView01"
            android:layout_width="57dp"
            android:layout_height="wrap_content"
            android:background="@drawable/icon1"/>

<TextView

  android:id="@+id/myTitle"
  android:text="This is my new title"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:textColor="@color/titletextcolor"
   />
</LinearLayout>

TitleBar.java

public class TitleBar extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final boolean customTitleSupported =
                requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);
        if (customTitleSupported) {
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                R.layout.titlebar);
        }
        final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
        if (myTitleText != null) {
            myTitleText.setText("NEW TITLE");
            // user can also set color using "Color" and then
            // "Color value constant"
            // myTitleText.setBackgroundColor(Color.GREEN);
        }
    }
}

strings.xml

strings.xml 파일은 values폴더 아래에 정의되어 있습니다.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, Set_Text_TitleBar!</string>
    <string name="app_name">Set_Text_TitleBar</string>
    <color name="titlebackgroundcolor">#3232CD</color>
    <color name="titletextcolor">#FFFF00</color>
</resources>

답변

매니페스트 파일에서 각 활동에 대한 레이블을 정의 할 수 있습니다.

활동의 일반적인 정의는 다음과 같습니다.

<activity
     android:name=".ui.myactivity"
     android:label="@string/Title Text" />

제목 텍스트는이 활동에 대한 문자열 자원의 ID로 대체되어야합니다.

제목 텍스트를 동적으로 설정하려는 경우 코드에서 제목 텍스트를 설정할 수도 있습니다.

setTitle(address.getCity());

이 줄을 사용하면 제목이 내 활동의 oncreate 메소드에서 특정 주소의 도시로 설정됩니다.


답변

당신은 프로그래밍 방식으로 사용하여 제목을 정의 할 수 있습니다 setTitle당신 내에서 Activity,이 방법 중 하나 받아 들일 수 String귀하의 정의 또는 ID values/strings.xml파일을. 예:

public class YourActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {

        setTitle(R.string.your_title);
        setContentView(R.layout.main);

    }
}

답변

다음 두 가지 방법 중 하나로 ActionBar 제목을 변경할 수 있습니다.

  1. 매니페스트 :의 매니페스트 파일에서 각 활동의 레이블을 설정하십시오.

    android:label="@string/TitleWhichYouWantToDisplay"
  2. 코드에서 : 코드에서, String 또는 id를 String으로하여 setTitle () 메소드를 호출하십시오.

    public class MainActivity extends Activity {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
    
            setTitle(R.string.TitleWhichYouWantToDisplay);
            // OR You can also use the line below
            // setTitle("MyTitle")
            setContentView(R.layout.activity_main);
    
        }
    }

답변

Activity.onCreate () 콜백 내부 또는 제목을 변경해야하는 다른 장소 :

getSupportActionBar().setTitle("Whatever title");

답변

이것을 시도하십시오 …

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
    this.setTitle(String.format(your_format_string, your_personal_text_to_display));
    setContentView(R.layout.your_layout);
       ...
       ...
}

그것은 나를 위해 작동


답변

조금 오래되었지만 같은 문제가있었습니다. 나는 이렇게했다 :

strings.xml

<string name="title_awesome_app">My Awesome App</string>

AndroidManifest.xml 에서 설정했는지 확인하십시오 .

<activity
            ...
            android:label="@string/title_awesome_app" >
            ...
</activity>

쉬우 며 null 참조 및 기타 사항에 대해 걱정할 필요가 없습니다.