嗨,我在日历应用程序中指出取消/完成按钮.这两个按钮固定在顶部,即使您滚动底部的“窗体”,它们总是可见的.
我可以知道,它是Action Bar的一部分吗?如果是这样,那么实现应该如何呢?
解决方法
请记住,Android是开源的,大多数应用程序预安装在运行aosp的Android设备上都是开源的.
这是项目:https://github.com/android/platform_packages_apps_calendar
是的,它是一个自定义的ActionBar设置,这里是XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:divider="?android:attr/dividerVertical"
android:dividerPadding="12dip
android:showDividers="middle">
<!-- id must match corresponding menu item id -->
<LinearLayout
android:id="@+id/action_cancel
style="@style/EditEventCustomActionButton">
<ImageView
android:src="@drawable/ic_menu_cancel_holo_light"
style="@style/EditEventCustomActionButtonImage" />
<TextView
android:text="@string/discard_label"
style="@style/EditEventCustomActionButtonText" />
</LinearLayout>
<!-- id must match corresponding menu item id -->
<LinearLayout
android:id="@+id/action_done"
style="@style/EditEventCustomActionButton">
<ImageView
android:src="@drawable/ic_menu_done_holo_light"
style="@style/EditEventCustomActionButtonImage" />
<TextView
android:text="@string/save_label"
style="@style/EditEventCustomActionButtonText" />
</LinearLayout
</LinearLayout>
稍后在运行时设置:
View actionBarButtons = inflater.inflate(R.layout.edit_event_custom_actionbar,new LinearLayout(mContext),false); View cancelActionView = actionBarButtons.findViewById(R.id.action_cancel); cancelActionView.setonClickListener(mActionBarListener); View doneActionView = actionBarButtons.findViewById(R.id.action_done); doneActionView.setonClickListener(mActionBarListener); mContext.getActionBar().setCustomView(actionBarButtons);
希望有所帮助