方法一(不推荐): 类似于MyStatsFragment,MyStatsFragment初始化xml2,然后取代要内置的占位的那一行xml1
方法二:<include>重用xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout android:id="@+id/content_frame" android:layout_width="fill_parent" android:layout_height="fill_parent" />
<include
android:id="@+id/left_drawer"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
layout="@layout/fragment_left_menu"
/>
</android.support.v4.widget.DrawerLayout>
http://developer.android.com/training/improving-layouts/reusing-layouts.html
ListView
ArrayAdatper and simpleAdapter
http://www.vogella.com/tutorials/AndroidListView/article.html
custom click:
adapter = new SimpleAdapter(getActivity(), list,
R.layout.pageview_timeline_cardview, from, to)
{
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
View view =super.getView(position, convertView, parent);
final int pos = position;
RelativeLayout rlayout=(RelativeLayout) view.findViewById(R.id.rgm_card);
rlayout.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Log.d(TAG, pos);
}
});
return view;
}
};
Action bar
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent intent = new Intent(this, ActOnThisActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; default: return super.onOptionsItemSelected(item); } }
ActionBar bar = getActionBar(); bar.setDisplayHomeAsUpEnabled(true);http://www.informit.com/articles/article.aspx?p=1743642&seqNum=4
Action bar with right hand side:
可能需要android-support-v7-appcompat.jar
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_search"
android:icon="@drawable/map_icon_default"
android:title="Checkin"
android:showAsAction="ifRoom" />
</menu>
//action bar right hand side
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.pathlist_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_search: openSearch(); return true; case R.id.action_compose: composeMessage(); return true; default: return super.onOptionsItemSelected(item); } }
Navigation Drawer
http://blog.csdn.net/xyz_lmn/article/details/12523895
https://developer.android.com/design/patterns/navigation-drawer.htmlhttps://www.codeofaninja.com/2014/02/android-navigation-drawer-example.html
Custom theme:
Custom theme
http://stackoverflow.com/questions/11675500/sherlock-actionbar-stylesDialog:
RecordDialogFragment dialog = new RecordDialogFragment();dialog.show(getFragmentManager(), "NoticeDialogFragment");
DialogFragment