在实际的应用过程中图片和视频的显示使用异步加载
一、点击title时切换图片和视频
1、修改AndroidManifest.xml文件,使用自定义主题
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/customTheme">
<activity
android:name="com.example.imageselector.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
2、在onCreate方法中添加
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
// Set the header.
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.action_bar);
3、写布局文件
4、Photo和Video的点击事件,点击时切换fragment,调用switchFragment方法
private void initFragment() {
this.photoPickerFragment = new PhotoAndVideoPickerFragment();
Bundle bundle = new Bundle();
bundle.putInt("fragmentIndex", 0);
this.photoPickerFragment.setArguments(bundle);
this.videoPickerFragment = new PhotoAndVideoPickerFragment();
Bundle videoBundle = new Bundle();
videoBundle.putInt("fragmentIndex", 1);
this.videoPickerFragment.setArguments(videoBundle);
switchFragment(photoPickerFragment);
this.currentFragment = this.photoPickerFragment;
}
private void switchFragment(PhotoAndVideoPickerFragment newFragment) {
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
if (null == this.currentFragment) {
transaction.add(R.id.picker_fragment_container, newFragment)
.commit();
} else {
if (currentFragment != newFragment) {
if