【问题标题】:Autoscrollable title in Android Actionbar (Marquee)Android 操作栏中的自动滚动标题(选取框)
【发布时间】:2012-04-05 19:16:42
【问题描述】:

如果 Android ActionBar 的标题太大,是否有可能使标题自动滚动(选框)?

【问题讨论】:

    标签: android android-widget android-actionbar android-scroll


    【解决方案1】:

    好吧,我已经这样做了:

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    
        try {
            Field f = toolbar.getClass().getDeclaredField("mTitleTextView");
            f.setAccessible(true);
            TextView toolbarTextView = (TextView) f.get(toolbar);
            toolbarTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
            toolbarTextView.setFocusable(true);
            toolbarTextView.setFocusableInTouchMode(true);
            toolbarTextView.requestFocus();
            toolbarTextView.setSingleLine(true);
            toolbarTextView.setSelected(true);
            toolbarTextView.setMarqueeRepeatLimit(-1);
    
            // set text on Textview
    
            toolbarTextView.setText("Hello Android ! This is a sample marquee text. That's great. Enjoy");
        } catch (NoSuchFieldException e) {
        } catch (IllegalAccessException e) {
        }
    

    希望这会对你有所帮助。

    【讨论】:

      【解决方案2】:

      您可以尝试实现我对this question 的回答并将android:ellipsize="marquee" 添加到TextView...?值得一试。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 2021-12-15
        • 2012-10-14
        • 1970-01-01
        相关资源
        最近更新 更多