【问题标题】:how to save text position in textview如何在textview中保存文本位置
【发布时间】:2013-09-26 06:24:39
【问题描述】:

我想要做的是在我的文本视图中阅读段落时以及出于任何原因

我退出应用程序或点击后退按钮如何让我的段落保存我正在阅读的位置。

我希望你能理解我,我试过这个但它不起作用(冻结)

<TextView
        android:id="@+id/id_dailyprayers_txt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:ems="10"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:gravity="center"
        android:shadowColor="@color/black"
        android:shadowDx="2"
        android:shadowDy="2"
        android:shadowRadius="1.5"
        android:text=""
        android:freezesText="true"
        android:textColor="@color/Vanilla"
        android:textSize="35sp" />

有什么帮助吗??

【问题讨论】:

标签: android textview


【解决方案1】:

您是否尝试过处理后退按钮按下并保存文本滚动并将其保存在 sharedPreference 中并在应用重新打开时加载它。

@Override
public void onBackPressed() {  
getApplicationContext().getSharedPreferences("myData", 0).edit().putInt("lastPos", tv.getScrollY());
super.onBackPressed();
}

并将其放入 onCreat

//first remember to defined tv
tv.scrollTo(0,getApplicationContext().getSharedPreferences("myData", 0).getInt("lastPos", 0)); 

问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 1970-01-01
    • 2021-05-29
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多