我创建了一个BottomSheetDialogFragment,我想调整它的最大扩展高度.我怎样才能做到这一点?我可以找回BottomSheetBehaviour但是我能找到的只是一个用于窥视高度的二传手,但是对于扩展的高度没什么.
public class DialogMediaDetails extends BottomSheetDialogFragment
{
@Override
public void setupDialog(Dialog dialog, int style)
{
super.setupDialog(dialog, style);
View view = View.inflate(getContext(), R.layout.dialog_media_details, null);
dialog.setContentView(view);
...
View bottomSheet = dialog.findViewById(R.id.design_bottom_sheet);
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setPeekHeight(...);
// how to set maximum expanded height???? Or a minimum top offset?
}
}
Run Code Online (Sandbox Code Playgroud)
编辑
我为什么需要那个?因为我BottomSheet在一个全屏活动中显示一个Dialog,如果BottomSheet在顶部留下一个空间,它看起来很糟糕......
android android-support-library androiddesignsupport bottom-sheet
我想在RecyclerView显示数据的同时更新,在我的情况下,我会显示带或不带标签的图像.
Defaultly我设置标签的可见性,当我创建视图持有人这很好,但我希望用户通过菜单更改标签的知名度,同时RecyclerView显示,所以我想手动更新中的所有现有视图的可视性RecyclerView.
我可以以某种方式得到所有现有的Views?我需要所有,不仅是可见的,我不希望以后回收View不更新...
编辑2
我现在设法通过使用https://code.google.com/p/android/issues/detail?id=42601#c10中的技巧摆脱错误,这就是为什么我的上一次编辑被置于顶部的原因我的问题
但这导致了下一个错误:
java.lang.NullPointerException
at android.support.v4.app.FragmentManagerImpl.getFragment(FragmentManager.java:569)
at android.support.v4.app.FragmentStatePagerAdapter.restoreState(FragmentStatePagerAdapter.java:211)
at android.support.v4.view.ViewPager.onRestoreInstanceState(ViewPager.java:1281)
at android.view.View.dispatchRestoreInstanceState(View.java:12043)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2688)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2694)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2694)
at android.view.View.restoreHierarchyState(View.java:12021)
at android.support.v4.app.Fragment.restoreViewState(Fragment.java:425)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:949)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4800)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
现在我不知道从哪里继续......
编辑0 - 第一个问题
我得到以下异常:
java.lang.IllegalStateException: No activity
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1091)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1877)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1492)
at android.support.v4.app._HoloFragment.performActivityCreated(_HoloFragment.java:251)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460) …Run Code Online (Sandbox Code Playgroud) 我想以UTC格式获取当前时间.到目前为止我所做的是(仅用于测试目的):
DateTime dt = new DateTime();
DateTimeZone tz = DateTimeZone.getDefault();
LocalDateTime nowLocal = new LocalDateTime();
DateTime nowUTC = nowLocal.toDateTime(DateTimeZone.UTC);
Date d1 = nowLocal.toDate();
Date d2 = nowUTC.toDate();
L.d("tz: " + tz.toString());
L.d("local: " + d1.toString());
L.d("utc: " + d2.toString());
Run Code Online (Sandbox Code Playgroud)
d1 是我当地的时间,没关系d2 是我当地时间+ 1,但应该是当地时间 - 1 ...我的本地时区是UTC + 1(根据调试输出和列表:https://www.joda.org/joda-time/timezones.html)...
如何正确地从一个时区转换为另一个时区(包括毫秒表示)?
编辑
我需要日期/毫秒...这不是关于正确显示时间....
编辑2
现在,在评论和答案的帮助下,我尝试了以下内容:
DateTimeZone tz = DateTimeZone.getDefault();
DateTime nowLocal = new DateTime();
LocalDateTime nowUTC = nowLocal.withZone(DateTimeZone.UTC).toLocalDateTime();
DateTime nowUTC2 = nowLocal.withZone(DateTimeZone.UTC);
Date dLocal = nowLocal.toDate(); …Run Code Online (Sandbox Code Playgroud) 到目前为止,我已经调整了我的代码ContextCompat.startForegroundService(context, intentService);来启动我的服务.这样,它适用于android <26和android 26(Oreo).
我仍然看到一个区别,在android oreo我没有看到我的自定义前景通知(我只看到"应用程序在后台运行"通知).我还需要调整任何东西吗?
我的服务如下:
public class BaseOverlayService extends Service {
@Override
public void onCreate() {
super.onCreate();
moveToForeground();
}
private void moveToForeground() {
Notification notification = ...;
super.startForeground(NOTIFICATION_ID, notification);
}
}
Run Code Online (Sandbox Code Playgroud)
官方的例子
此示例(https://github.com/googlesamples/android-play-location/blob/master/LocationUpdatesForegroundService/app/src/main/java/com/google/android/gms/location/sample/locationupdatesforegroundservice/LocationUpdatesService.java #L200)显示为评论,我应该使用以下,但startServiceInForeground不存在......
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
NotificationManager mNotificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
mNotificationManager.startServiceInForeground(new Intent(this, BaseOverlayService.class), NOTIFICATION_ID, notification);
} else {
startForeground(NOTIFICATION_ID, notification);
}
Run Code Online (Sandbox Code Playgroud)
编辑
我的通知是这样创建的,它正在使用API <26的数千个Android设备上工作到现在为止:
protected Notification foregroundNotification(int notificationId)
{
boolean paused = MainApp.getPrefs().sidebarServicePaused();
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); …Run Code Online (Sandbox Code Playgroud) android android-notifications foreground-service android-8.0-oreo
我有以下设置:
Fragment 同 RecyclerViewandroid:fitsSystemWindows="true"xml布局中的相应值问题是,在这种情况下我无法使状态栏透明.我的工作如下:
然后我尝试调整活动以编程方式获得如下的半透明工具栏:
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void themeNavAndStatusBar(Activity activity)
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
return;
Window w = activity.getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
w.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
w.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
w.setNavigationBarColor(activity.getResources().getColor(android.R.color.transparent));
w.setStatusBarColor(activity.getResources().getColor(android.R.color.transparent));
}
Run Code Online (Sandbox Code Playgroud)将@+id/frame_containerfragment ()中的占位符替换为片段
在这种情况下,状态栏是纯色的,并且未在其下方绘制视图...为什么?
我想要的是
我想要一个工具栏,它滚动屏幕并完全隐藏,而此工具栏下面的内容应该适合屏幕,并在透明导航栏后面绘制.
布局
这是我的主要活动:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/clMain"
android:fitsSystemWindows="true"
android:background="?attr/main_background_color"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:fitsSystemWindows="true"
android:background="@null"
app:elevation="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="?actionBarThemeStyle"
app:popupTheme="?actionBarPopupThemeStyle"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"> …Run Code Online (Sandbox Code Playgroud) 如何正确使用碎片中的碎片?
我的(简化)用例如下,我有一个带有布局片段的活动,这个片段自己包含一个子片段...所有片段都手动添加到他们的父母......
----------------------------------------------------------
- Activity -
- -
- -
- --------------------------------------- -
- - Fragment - -
- - - -
- - ----------------- - -
- - - SubFragment - - -
- - - - - -
- - - - - -
- - ----------------- - -
- --------------------------------------- -
- -
----------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
现在在我的活动中onCreate我做了以下事情:
if (savedInstanceState == null)
{
// I create the fragment
mMainFragment = new MainFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_main, mMainFragment); …Run Code Online (Sandbox Code Playgroud) 我如何听取最后解雇BottomSheetDialogFragment?我想在最终解雇时保存用户更改...
我试过以下:
方法1
如果通过向下滑动对话框解除对话(不在背面按压或外面触摸),则仅触发此操作
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
Dialog d = super.onCreateDialog(savedInstanceState);
d.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
BottomSheetDialog d = (BottomSheetDialog) dialog;
FrameLayout bottomSheet = (FrameLayout) dialog.findViewById(android.support.design.R.id.design_bottom_sheet);
BottomSheetBehavior behaviour = BottomSheetBehavior.from(bottomSheet);
behaviour.setState(BottomSheetBehavior.STATE_EXPANDED);
behaviour.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN)
{
// Bottom Sheet was dismissed by user! But this is only fired, if dialog is swiped down! Not if touch outside dismissed the …Run Code Online (Sandbox Code Playgroud) android dialog android-dialogfragment dialogfragment bottom-sheet
我想从列表视图转到详细视图,因此,我OnClickListener在列表中使用以下内容:
@Override
public void onClick(View view)
{
Bet bet = (Bet)view.getTag();
FragmentManager fm = getActivity().getSupportFragmentManager();
BetDetailFragment f = BetDetailFragment.create(bet);
String tag = f.getClass().getName();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
setSharedElementReturnTransition(TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.move));
f.setSharedElementEnterTransition(TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.move));
}
FragmentTransaction ft = fm.beginTransaction()
.replace(R.id.frame_container, f, tag)
.addToBackStack(tag);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
L.d(this, "TRANS: " + TransitionUtil.getTransitionNameBetLogo1(bet) + "|" + view.findViewById(R.id.ivLogo1));
L.d(this, "TRANS: " + TransitionUtil.getTransitionNameBetLogo2(bet) + "|" + view.findViewById(R.id.ivLogo2));
ft.addSharedElement(view.findViewById(R.id.ivLogo1), "1");//TransitionUtil.getTransitionNameBetLogo1(bet));
ft.addSharedElement(view.findViewById(R.id.ivLogo2), "2");//TransitionUtil.getTransitionNameBetLogo2(bet));
}
ft.commit();
}
Run Code Online (Sandbox Code Playgroud)
我的函数返回唯一的名称,我有两个不同的视图,但它仍然无法正常工作.我已经评论过不必要的函数并在那里写了一些独特的事务名称......但是,我仍然得到这个例外,在第一行addSharedElement:
java.lang.IllegalArgumentException: Unique transitionNames are required for …Run Code Online (Sandbox Code Playgroud) android transition transactions fragment android-transitions
我想创建以下内容的observable:
我想使用BehaviorSubject<Boolean>as触发器并将此触发器绑定到activity onResume和onPause事件.(附加代码示例)
题
我已经设置了一些东西,但它没有按预期工作.我用它如下:
Observable o = ...;
// Variant 1
o = o.lift(new RxValve(getPauser(), 1000, getPauser().getValue())
// Variant 2
// o = o.compose(RXPauser.applyPauser(getPauser()));
o
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
Run Code Online (Sandbox Code Playgroud)
目前的问题是,Variant 1应该可以正常工作,但有时,事件只是没有发出 - 阀门没有发射,直到阀门一切正常工作(可能是一个穿线问题......)!解决方案2更简单,似乎有效,但我不确定它是否真的更好,我不这么认为.我实际上不确定,为什么解决方案有时会失败,所以我不确定解决方案2是否解决了(目前对我不知道)问题...
有人可以告诉我可能是什么问题或者简单的解决方案应该可靠地工作吗?或者给我一个可靠的解决方案?
码
RxValue
https://gist.github.com/akarnokd/1c54e5a4f64f9b1e46bdcf62b4222f08
RXPauser功能
public static <T> Observable.Transformer<T, T> applyPauser(Observable<Boolean> pauser)
{
return observable -> pauser(observable, pauser);
}
private static <T> Observable<T> pauser(Observable<T> source, Observable<Boolean> pauser)
{
// this observable buffers all items that are emitted while …Run Code Online (Sandbox Code Playgroud) android ×9
bottom-sheet ×2
fragment ×2
dialog ×1
java ×1
jodatime ×1
observable ×1
rx-java ×1
toolbar ×1
transactions ×1
transition ×1