編輯:關於android開發
1 <!-- Wifi --> 2 <dashboard-tile 3 android:id="@+id/wifi_settings" 4 android:fragment="com.android.settings.wifi.WifiSettings" 5 android:icon="@drawable/sunmi_wifi" 6 android:title="@string/wifi_settings_title" /> 7 <!-- 移動網絡 --> 8 <dashboard-tile 9 android:id="@+id/mobile_net_settings" 10 android:icon="@drawable/sunmi_network" 11 android:title="@string/network_settings_title" > 12 <intent 13 android:action="android.intent.action.MAIN" 14 android:targetClass="com.android.phone.MobileNetworkSettings" 15 android:targetPackage="com.android.phone" /> 16 </dashboard-tile>
這是設置中的wifi,和移動網絡選項,一個是添加fragment ,另一個是添加intent
解析這個xml是在SettingActivity中的loadCategoriesFromResource(R.xml.dashboard_categories, categories);方法中,
1 private void rebuildUI(Context context) {
2 if (!isAdded()) {
3 return;
4 }
5 final Resources res = getResources();
6 mDashboard.removeAllViews();
7 List<DashboardCategory> categories = ((SettingsActivity) context).getDashboardCategories(true);
8 final int count = categories.size();
9 for (int n = 0; n < count; n++) {
10 DashboardCategory category = categories.get(n);
11 View categoryView = mLayoutInflater.inflate(R.layout.dashboard_category, mDashboard, false);
12 TextView categoryLabel = (TextView) categoryView.findViewById(R.id.category_title);
13 categoryLabel.setText(category.getTitle(res));
14
15 ViewGroup categoryContent = (ViewGroup) categoryView.findViewById(R.id.category_content);
16
17 final int tilesCount = category.getTilesCount();
18 for (int i = 0; i < tilesCount; i++) {
19 DashboardTile tile = category.getTile(i);
20 DashboardTileView tileView = new DashboardTileView(context);
21 updateTileView(context, res, tile, tileView.getImageView(), tileView.getTitleTextView(),
22 tileView.getStatusTextView());
23
24 tileView.setTile(tile);
25 categoryContent.addView(tileView);
26 }
27
28 // Add the category
29 mDashboard.addView(categoryView);
30 }
31 }
分析源碼可知rebuildui()是將xml中解析的實體類,構建成對應的view(categoryView,DashboardTileView)在這並沒有看到添加點擊事件,所以猜測應該寫到DashboardTileView中了
1 public class DashboardTileView extends FrameLayout implements View.OnClickListener
看到這裡就知道是在這裡實現點擊事件處理的
1 @Override
2 public void onClick(View v) {
3 if (mTile.fragment != null) {
4 Utils.startWithFragment(getContext(), mTile.fragment, mTile.fragmentArguments, null, 0,
5 mTile.titleRes, mTile.getTitle(getResources()));
6 } else if (mTile.intent != null) {
7 getContext().startActivity(mTile.intent);
8 }
9 }
看到這裡一目了然啦,可以知道fragment 優先級>intent
再來看fragment的跳轉
1 public static void startWithFragment(Context context, String fragmentName, Bundle args,
2 Fragment resultTo, int resultRequestCode, int titleResId,
3 CharSequence title) {
4 startWithFragment(context, fragmentName, args, resultTo, resultRequestCode,
5 null /* titleResPackageName */, titleResId, title, false /* not a shortcut */);
6 }
7
8 public static void startWithFragment(Context context, String fragmentName, Bundle args,
9 Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,
10 CharSequence title, boolean isShortcut) {
11 Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName,
12 titleResId, title, isShortcut);
13 if (resultTo == null) {
14 context.startActivity(intent);
15 } else {
16 resultTo.startActivityForResult(intent, resultRequestCode);
17 }
18 }
19
20 public static Intent onBuildStartFragmentIntent(Context context, String fragmentName,
21 Bundle args, String titleResPackageName, int titleResId, CharSequence title,
22 boolean isShortcut) {
23 Intent intent = new Intent(Intent.ACTION_MAIN);
24 intent.setClass(context, SubSettings.class);
25 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName);
26 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
27 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME,
28 titleResPackageName);
29 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleResId);
30 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);
31 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, isShortcut);
32 return intent;
33 }
可以知道是通過構建一個帶fragmentName參數的intent來啟動SubSettings.class
而SubSettings.class中並沒有實現具體添加fragment,在父類SettingsActivity中oncrreate()中獲取具體參數,添加對應fragment
點擊Setting 之dashboard 點擊跳轉流程就是這樣啦
轉自:http://blog.csdn.net/kingyc123456789/article/details/53175624
全新的手勢,側滑返回、全局右滑返回都OUT啦!,全局out
全新的手勢,側滑返回、全局右滑返回都OUT啦!,全局out前言 Android快速開發框架-ZBLibrary 最近將以前的 全局右滑返回 手勢功能改成了 底部左右滑動手
H5調用Android播放視頻,h5調用android
H5調用Android播放視頻,h5調用androidwebView.loadUrl(http://10.0.2.2:8080/assets/RealNetJSCallJ
Android中使用Notification實現進度通知欄(示例三),notification進度條
Android中使用Notification實現進度通知欄(示例三),notification進度條我們在使用APP的過程中,軟件會偶爾提示我們進行版本更新,我們點擊確認
HBase & thrift & C++編程
HBase & thrift & C++編程HBase & thrift & C++編程.pdf目錄目錄11.前言12.啟動和停止thrift2 12.1