嗨,我正在使用 Caldroid 日历,我只使用来自官方网站的初始化代码getFragmentManager()
因为getSupportFragmentManager()
我在类中使用从 Fragment 而不是 Activity 扩展的代码。MysTab 是 TabbedActivity 的片段。结果我有 2 个日历,我不知道为什么。有任何想法吗?
截屏
public class MysTab extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.logs_tab, container, false);
CaldroidFragment caldroidFragment = new CaldroidFragment();
Bundle args = new Bundle();
Calendar cal = Calendar.getInstance();
args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1);
args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR));
caldroidFragment.setArguments(args);
FragmentTransaction t = getFragmentManager().beginTransaction();
t.replace(R.id.caldroidCal, caldroidFragment);
t.commit();
return rootView;
}
}
布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<fragment
android:id="@+id/caldroidCal"
android:name="com.roomorama.caldroid.CaldroidFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</LinearLayout>