从RemoteViews获取TextView以使其文本可滚动 [英] Get TextView from RemoteViews to make its text scrollable
本文介绍了从RemoteViews获取TextView以使其文本可滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个通过服务的RemoteView构建的通知.
I have a notification built with a RemoteView from a service.
RemoteView布局包含一个我要滚动的TextView.
The RemoteView layout contains a TextView that I want to have it scrolling.
我已经将它设置为xml中的选取框,一切都很好.但是现在我需要设置textView.setSelected(true)
,因此我需要以某种方式引用textView.
I've set it up as marquee in the xml, all good. But now I need to set textView.setSelected(true)
therefore I need to somehow reference the textView.
那么我该如何从RemoteView获取textView来进行setSelected()?还是有另一种方法可以使其在通知中滚动?
So how do I get the textView from the RemoteView to do setSelected()? Or is there another way to make it scrolling in the notification?
我尝试过
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>
推荐答案
这就足够了:
<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>
这篇关于从RemoteViews获取TextView以使其文本可滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文