我正在编写一段代码,当屏幕方向改变时,会改变TextView的文本。我使用onConfigurationChanged()监听器来改变文本。
override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig)
val orientation : Int = getResources().getConfiguration().orientation
val oTag = "Orientation Change"
if(orientation == (Configuration.ORIENTATION_LANDSCAPE)){
mytext?.setText("Changed to Landscape")
Log.i(oTag, "Orientation Changed to Landscape")
}else if (orientation == (Configuration.ORIENTATION_PORTRAIT)){
mytext?.setText("Changed to Portratit")
Log.i(oTag, "Orientation Changed to Portratit")
}else{
Log.i(oTag, "Nothing is coming!!")
}
}
但是什么也没有发生,甚至连日志中都没有任何信息。
我还在清单文件中为我的活动添加了这个属性。
android:configChanges="orientation"
这是什么地方出了问题?还有其他实现方法吗?