适配中英文切换
This commit is contained in:
@@ -10,6 +10,8 @@ import com.bumptech.glide.Glide
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.databinding.PersonalFragmentBinding
|
||||
import com.example.defenseapplication.personal.PersonalProfileActivity
|
||||
import com.example.defenseapplication.utils.LanguageUtil
|
||||
import com.example.defenseapplication.view.LanguageDialog
|
||||
import com.gyf.immersionbar.ImmersionBar
|
||||
|
||||
class PersonalFragment : Fragment() {
|
||||
@@ -37,9 +39,36 @@ class PersonalFragment : Fragment() {
|
||||
val intent= Intent(requireContext(), PersonalProfileActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
// 更新当前语言显示
|
||||
updateCurrentLanguageDisplay()
|
||||
// 语言设置点击事件
|
||||
binding.itemLanguage.setOnClickListener {
|
||||
showLanguageDialog()
|
||||
}
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新当前语言显示
|
||||
*/
|
||||
private fun updateCurrentLanguageDisplay() {
|
||||
val currentLang = LanguageUtil.getCurrentLanguage(requireContext())
|
||||
binding.tvCurrentLanguage.text = LanguageUtil.getLanguageDisplayName(currentLang)
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示语言选择对话框
|
||||
*/
|
||||
private fun showLanguageDialog() {
|
||||
val dialog = LanguageDialog(requireContext()) { language ->
|
||||
LanguageUtil.switchLanguage(requireContext(), language)
|
||||
// 刷新当前页面以应用新语言
|
||||
requireActivity().recreate()
|
||||
}
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null // 避免内存泄漏
|
||||
|
||||
Reference in New Issue
Block a user