在xml文件的Preference标签中,用<extra>给<intent>标签加参数

前端之家收集整理的这篇文章主要介绍了在xml文件的Preference标签中,用<extra>给<intent>标签加参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在xml文件的Preference标签中,用<extra>给<Intent>标签加参数,以及<intent>标签的android:targetPackage和android:targetClass属性使用注意事项

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
  3. <Preference
  4. android:title="prefs_category_one"
  5. android:summary="prefs_summary_category_one">
  6. <!-- 这里android:targetPackage是应用程序的Context,而android:targetClass的路径在子包settings下 -->
  7. <!-- 如果把 android:targetPackage="com.demo.artshell.uidemo.settings" 运行时找不到Activity -->
  8. <intent
  9. android:action="prefs_category_action_ONE"
  10. android:targetPackage="com.demo.artshell.uidemo"
  11. android:targetClass="com.demo.artshell.uidemo.settings.SupportOldVersionAndReusedActivityOrFragment$ReusedActivity">
  12. <!-- 官网没有说明,但确实可以通过<extra>传附加信息 getIntent().getStringExtra("reused_key") -->
  13. <extra
  14. android:name="reused_key"
  15. android:value="reused_fragment_two"/>
  16. </intent>
  17. </Preference>
  18.  
  19. <Preference
  20. android:title="prefs_category_two"
  21. android:summary="prefs_summary_category_two">
  22. <intent
  23. android:action="prefs_category_action_TWO"
  24. android:targetPackage="com.demo.artshell.uidemo"
  25. android:targetClass="com.demo.artshell.uidemo.settings.SupportOldVersionAndReusedActivityOrFragment$ReusedActivity"/>
  26. </Preference>
  27. </PreferenceScreen>

猜你在找的XML相关文章