如何在textview中保存文本位置

时间:2013-09-25 21:44:36

标签: android textview

我想要做的是在我的textview中阅读段落,无论出于何种原因

我退出了应用程序,或者我点击后退按钮如何让我的段落保存我正在阅读的地方。

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

<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" />

任何帮助??

1 个答案:

答案 0 :(得分:0)

您是否尝试过按下后退按钮并保存文本滚动并将其保存在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)); 

此致

相关问题