android - 如何使用列表首选项收听点击并立即更改语言
问题描述
这是我的代码:
public class SettingsPage extends AppCompatActivity {
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.notification_setting)
RelativeLayout notification_setting;
@BindView(R.id.setting_back_image)
ImageView setting_back_image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
setting_back_image.setOnClickListener(v -> onBackPressed());
notification_setting.setOnClickListener(v -> {
Intent settingsIntent = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
settingsIntent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName())
.putExtra(Settings.EXTRA_CHANNEL_ID, 1);
}
startActivity(settingsIntent);
});
getFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyPreferenceFragment()).commit();
}
public static class MyPreferenceFragment extends PreferenceFragment
{
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
解决方案
推荐阅读
- java - Java将JFIF文件转换为JPG文件
- java - 写入和保存文件并打开它
- javascript - 哪个 RxJS Observable 运算符实现惰性/动态 forkJoin 行为
- reactjs - 如何在混合场景中使用 ReactJS
- java - 重构闭包条件以修复列表中的最大表达式数为 1000
- c++ - C++ 编程:作业的输出略微关闭
- scala - 使用reduceByKey时在scala中类型不匹配
- javascript - csv格式问题javascript p5
- scikit-learn - CountVectorizer 上的词形还原不会删除停用词
- azure - Xamarin.Forms 绑定 - 相同的属性值绑定到 ListView 中的每个项目