【问题标题】:Custom notification marquee text doesnt work android自定义通知字幕文本不起作用android
【发布时间】:2012-11-24 07:52:30
【问题描述】:

您好,我试图在通知管理器字幕中添加我的文本的一部分,但没有用,我试过这个:

  <TextView
    android:id="@+id/title_text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:gravity="bottom"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"                                     
    android:focusable="true"
    android:focusableInTouchMode="true"              
    android:singleLine="true"
    android:textSize="15sp"
    android:textStyle="bold" >
  </TextView>

在我的 .java 中我使用 remoteview:

Notification notification = new Notification(icon, tickerText, when);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);

contentView.setTextViewText(R.id.title_text, "This is a very long text which is not fitting in the screen so it needs to be marqueed");

我想为该title_text设置字幕这是一个很长的文本,不适合屏幕,因此需要进行字幕

但是选框不工作只是保持静止我能做什么?

谢谢。

【问题讨论】:

    标签: android android-notifications


    【解决方案1】:

    我更改了我的 xml:

      <TextView
        android:id="@+id/title_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:gravity="bottom"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="false"                                     
        android:focusable="true"
        android:focusableInTouchMode="true"              
        android:singleLine="true"
        android:textSize="15sp"
        android:textStyle="bold" 
        android:textColor="#fff">
        <requestFocus/> 
      </TextView>
    

    我添加了&lt;requestFocus/&gt;,现在我的选框完美了。

    【讨论】:

    • 只是因为我很好奇,你会尝试将 scrollHorizo​​ntally 设置回 true 看看它是否有效?
    • 如果我将其设置为 true 但如果我删除 &lt;requestFocus/&gt; 则根本不起作用。
    • 它非常有用。我尝试解决这个问题大约 4 天 :-D
    • 从我所读到的,它似乎只在选择目标文本字段时才有效。这就是为什么它有效:)
    • 它确实有效,但我需要尝试展开通知才能开始。即使使用 requestFocus。
    【解决方案2】:

    根据docs,将 scrollHorizo​​ntally 属性设置为 true 将不会在边缘换行。尝试将其设置为 false,以便使用 ellipsize 属性。

    【讨论】:

    • 不起作用 :( 我将它设置为 false 但同样的选框不起作用
    【解决方案3】:

    我花了一天的时间才意识到这是通过 NotificationCompat.Builder: setTicker 支持 RemoteView 的这种方法完成的选框效果

    我真的希望这个答案能挽救许多人的生命 :)(差点掉头发)

    【讨论】:

    • 不使用 .setCustomBigContentView(remoteViewsSetFromCustomLayout)
    • /** * 设置发送到无障碍服务的“ticker”文本。在 * {@link Build.VERSION_CODES#LOLLIPOP} 之前,设置通知首次到达时在状态栏中显示的文本 * 以及可能在某些设备上显示 * 的 RemoteViews 对象。 */
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 2018-11-07
    • 2020-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多