English 中文(简体)
Android 中的自定义标题和设置符号
原标题:Custom title and setTitle in Android

我创造了一个简单的自定义标题, 它正在完美地显示。 但我不确定给我的文本View 以什么代号 才能让 SetTitle 方法发挥它的魔力 。

我的第一个选择是@android:id/标题,

Example I have defined a custom title layout in xml and added it to my activity.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_title"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/transparent" >

    <ImageView
        android:id="@+id/logo"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="5dp"
        android:scaleType="centerInside"
        android:onClick="home"
        android:src="@drawable/logo" />

    <TextView
        android:id="@android:id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:textSize="18dp"
        android:textStyle="bold"
        android:layout_centerVertical="true"
        android:text="TextView" />
</RelativeLayout>

TextView 现在是“ 标题” 容器。 我想要的是“ 机器人 ” : 将清单中的标签值自动放入新标题 TextView 。

Ie. 默认方法设置 title 必须在某种定义的视图 ID 上添加此值 - 我只是需要该 ID 。

最佳回答

我不得不用一个自定义标题来创建类似的特性。 我非常怀疑你能否通过匹配一个代号来做到这一点, 如果Android允许的话, 这将是一个巨大的安全缺陷。 我所做的是扩展活动, 然后用像...

TextView mCustomTitle;

@Override
public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.myLayout);
     mCustomTitle = (TextView)findViewById(R.id.title);
}

@Override
public void setTitle(CharSequence title) {
    //you can override the other setTitle as well if you need it
    mCustomTitle.setText(title);        
}
问题回答

setTitle sets the title of the activity, it has nothing to do with TextView s you need to use setText() to set the text of a TextView:

(( TextView) finddViewById (R. id. text_view_id)) setText (“ TextView text”); (“ TextView text ”); (“ TextView 文本 ”)

EDIT: 检查此解决方案 - & gt; < a href="https://stackoverflow.com/ questions/2416844/how- to- set- kind- title- bar- textview- value- alive- in- and- mid " > 如何以动态方式设置自定义标题栏 TextView 值?





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签