TextView中的操作栏操作、TextView

由网友(微笑听雨)分享简介:我想添加一个TextView的动作条,我可以动态地修改。为什么低于code不工作???? < XML版本=1.0编码=UTF-8&GT?;< TextView中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android机器人:ID =@机器人:ID /...

我想添加一个TextView的动作条,我可以动态地修改。 为什么低于code不工作????

 < XML版本=1.0编码=UTF-8&GT?;
    < TextView中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:ID =@机器人:ID / text1中
        风格=@风格/ TextMedium
        机器人:以下属性来=5DP
        机器人:单线=真
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:ellipsize =金字招牌/>
 

在活动的onCreate方法,

 查看addView = getLayoutInflater()膨胀(R.layout.spinner_select_text,空)。
        actionBar.setCustomView(addView,新ActionBar.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        TextView的标签=(TextView中)addView.findViewById(android.R.id.text1);
        label.setText(你好);
 

解决方案 Android中 TextView的使用

您还需要 actionBar.setDisplayShowCustomEnabled(真);

仅供参考,你可以给的,而不是自己膨胀它的操作栏布局ID:

  actionBar.setDisplayShowCustomEnabled(真正的);
    actionBar.setCustomView(R.layout.spinner_select_text);

    TextView的标签=(TextView中)actionBar.getCustomView()findViewById(android.R.id.text1)。
 

I am trying to add a textView on the actionBar which I can dynamically edit. Why is the below code not working????

<?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@android:id/text1"
        style="@style/TextMedium"
        android:paddingLeft="5dp"
        android:singleLine="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee" />

In the onCreate method of activity,

View addView = getLayoutInflater().inflate(R.layout.spinner_select_text, null);
        actionBar.setCustomView(addView,new ActionBar.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        TextView label =  (TextView)addView.findViewById(android.R.id.text1);
        label.setText("Hello");

解决方案

You also need actionBar.setDisplayShowCustomEnabled(true);

FYI you can give the action bar your layout id instead of inflating it yourself:

    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(R.layout.spinner_select_text);

    TextView label = (TextView) actionBar.getCustomView().findViewById(android.R.id.text1);

阅读全文

相关推荐

最新文章