【发布时间】:2015-08-03 23:39:56
【问题描述】:
我想在我的 RemoteView 中有一个带有选框效果的 TextView
我有这个布局 XML 描述了我的 RemoteView (R.layout.notification_loading_small) 的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="64dip"
android:background="@color/primary_background_inverted">
<ProgressBar android:indeterminate="true"
android:layout_width="64dip"
android:layout_height="64dip"
android:id="@+id/marker_progress" style="?android:attr/progressBarStyle"
android:layout_gravity="center_vertical|center_horizontal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical"
android:padding="@dimen/padding_small"
android:gravity="center_vertical">
<TextView
android:id="@+id/notification_small_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@color/primary_textcolor_inverted"
android:textSize="@dimen/text_size_large"
android:text="@string/loading"/>
<TextView
android:id="@+id/notification_small_textview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@color/secondary_textcolor_inverted"
android:textSize="@dimen/text_size_small"
android:text="@string/loading_advice"/>
</LinearLayout>
</LinearLayout>
我的 Java 中的一个方法是这样的:
public void createTestNotification() {
mSmallLoadingNotificationView = new RemoteViews(getPackageName(), R.layout.notification_loading_small);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
PlayerService.this)
.setSmallIcon(R.drawable.ic_notification).setContentTitle(APP_NAME)
.setOngoing(true).setPriority(NotificationCompat.PRIORITY_MAX)
.setContent(mSmallLoadingNotificationView);
mNotification = builder.build();
startForeground(PLAYERSERVICE_NOTIFICATION_ID, mNotification);
}
我想让 id/notification_small_textview2 中的文本水平选框,但到目前为止这似乎是一项不可能完成的任务......
根据网上我需要添加 android:ellipsize="marquee", android:marqueeRepeatLimit="marquee_forever", android:lines="1 " 和 android:singleLine="true" 在我的 TextView 中。似乎我们还需要从 Java 中的 TextView 调用方法 setSelected(true)。但是我找不到用那种方法来做到这一点......我错过了什么?
我应该如何修改我的 Java 代码才能使选取框正常工作?
【问题讨论】:
标签: android performance android-layout android-fragments remoteview