【问题标题】:Get TextView from RemoteViews to make its text scrollable从 RemoteViews 获取 TextView 以使其文本可滚动
【发布时间】:2014-10-14 11:12:11
【问题描述】:

我有一个使用来自服务的 RemoteView 构建的通知。

RemoteView 布局包含一个我想让它滚动的 TextView。

我已经在 xml 中将它设置为选取框,一切都很好。但现在我需要设置textView.setSelected(true),因此我需要以某种方式引用textView。

那么如何从 RemoteView 获取 textView 来执行 setSelected()?还是有其他方法可以让它在通知中滚动?

我试过了

        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.notification, null);
        TextView text = (TextView) layout.findViewById(R.id.text);
        text.setSelected(true);

         View v = views.apply(getApplicationContext(), null);
         TextView text = (TextView) v.findViewById(R.id.text);
         text.setSelected(true);

但文本没有滚动..

这是我的 xml:

<TextView
    android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:duplicateParentState="true"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:gravity="center"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="false"
    android:singleLine="true" >

    <requestFocus
        android:duplicateParentState="true"
        android:focusable="true"
        android:focusableInTouchMode="true" />
</TextView>

【问题讨论】:

    标签: android scroll textview android-service remoteview


    【解决方案1】:

    这就够了:

    <TextView 
    android:id="@+id/text" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:duplicateParentState="true" 
    android:ellipsize="marquee" 
    android:fadingEdge="horizontal" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:gravity="center" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:scrollHorizontally="false" 
    android:singleLine="true" > 
        <requestFocus android:duplicateParentState="true" 
            android:focusable="true" 
            android:focusableInTouchMode="true" /> 
    </TextView>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      • 2018-07-20
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      相关资源
      最近更新 更多