小编Thu*_*oid的帖子

订阅Angular 2中的route params和queryParams

我已经设置了以下路由系统

export const MyRoutes: Routes = [
    {path: '', redirectTo: 'new', pathMatch: 'full'},
    {path: ':type', component: MyComponent}
];
Run Code Online (Sandbox Code Playgroud)

并有以下导航系统

goToPage('new');
goToPageNo('new', 2);

goToPage(type) {
    this.router.navigate([type]);
}
goToPageNo(type, pageNo) {
    this.router.navigate([type], {queryParams: {page: pageNo}});
}
Run Code Online (Sandbox Code Playgroud)

示例网址如下所示

HTTP://本地主机:3000 /新

HTTP://本地主机:3000 /新页= 2

HTTP://本地主机:3000 /更新

HTTP://本地主机:3000 /更新的页面= 5

有时他们有可选的 queryParams(页面)

现在我需要读取route params和queryParams

ngOnInit(): void {
    this.paramsSubscription = this.route.params.subscribe((param: any) => {
        this.type = param['type'];
        this.querySubscription = this.route.queryParams.subscribe((queryParam: any) => {
            this.page = queryParam['page'];
            if (this.page)
                this.goToPageNo(this.type, …
Run Code Online (Sandbox Code Playgroud)

rxjs angular

25
推荐指数
6
解决办法
2万
查看次数

RecyclerView上的快速点击(点击)会打开多个片段

我已经在我的ViewHolder上为我的RecyclerView实现了onClick监听器

但是当我执行非常快速的双击或鼠标点击时,它执行任务(在这种情况下打开一个单独的片段)两次或三次.

这是我的代码

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    TextView tvTitle, tvDescription;

    public ViewHolder(View itemView) {
        super(itemView);
        itemView.setClickable(true);
        itemView.setOnClickListener(this);

        tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        tvDescription = (TextView) itemView.findViewById(R.id.tv_description);
    }

    @Override
    public void onClick(View v) {
        mListener.onClick(FRAGMENT_VIEW, getAdapterPosition()); // open FRAGMENT_VIEW
    }
}
Run Code Online (Sandbox Code Playgroud)

关于如何防止这种行为的任何想法?

android android-adapter android-fragments onclicklistener android-recyclerview

12
推荐指数
4
解决办法
8008
查看次数

DialogPreference导致错误onDisplayPreferenceDialog()

我想创建一个简单的(是/否)对话框首选项,我按照这篇文章中的答案 - 从XML创建一个DialogPreference

但我得到一个错误说

java.lang.IllegalArgumentException: Tried to display dialog for unknown preference type. Did you forget to override onDisplayPreferenceDialog()?
    at android.support.v7.preference.PreferenceFragmentCompat.onDisplayPreferenceDialog(PreferenceFragmentCompat.java:647)
    at android.support.v7.preference.PreferenceManager.showDialog(PreferenceManager.java:553)
    at android.support.v7.preference.DialogPreference.onClick(DialogPreference.java:262)
    at android.support.v7.preference.Preference.performClick(Preference.java:1115)
    at android.support.v7.preference.Preference.performClick(Preference.java:1100)
    at android.support.v7.preference.Preference$1.onClick(Preference.java:170)
    at android.view.View.performClick(View.java:4756)
    at android.view.View$PerformClick.run(View.java:19749)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Run Code Online (Sandbox Code Playgroud)

我的XML

  <android.support.v7.preference.PreferenceCategory android:title="History &amp; privacy">

    <com.game.prefs.views.DialogPref
        android:key="pref_clear_search"
        android:title="Reset Quests"
        android:summary="Reset all quest-progress."
        android:dialogMessage="Are you sure you wish to reset your quest progress? This action cannot be undone!"
        android:positiveButtonText="Clear …
Run Code Online (Sandbox Code Playgroud)

android illegalargumentexception android-preferences android-dialog dialog-preference

8
推荐指数
1
解决办法
1815
查看次数

Android中的半透明状态栏

我使用以下布局(main_activity.xml)

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/text_margin"
        android:fitsSystemWindows="true"
        android:text="@string/large_text" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

使用以下样式-v21

<resources>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)

但我仍然无法存档透明状态栏

它看起来像这样

非透明

但是我想要这样的东西(新的Google报亭应用)

透明状态栏

注意:我正在使用

compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:support-v4:25.1.1'
compile 'com.android.support:design:25.1.1'
Run Code Online (Sandbox Code Playgroud)

android android-layout android-view

7
推荐指数
2
解决办法
3万
查看次数

Android下拉按钮

这个下拉按钮是什么?它看起来像一个微调器,可以在这里找到动画.

我尝试使用微调器,但它不一样.这一个看起来很棒!任何人都可以帮我找到它吗?我需要创造类似的东西.

android android-layout android-spinner drop-down-menu material-design

6
推荐指数
1
解决办法
8893
查看次数

DialogFragment使用接口回调到Target Fragment

我试图将一些数据从a dialogfragment发送到目标,fragment但它无法正常工作.

我写了以下代码,但它通过exception:

java.lang.NullPointerException: Attempt to invoke interface method 'void com.x.x.FragmentAlertDialog$Communicator.setI(java.lang.String)' on a null object reference
Run Code Online (Sandbox Code Playgroud)

码:

public class FragmentAlertDialog extends DialogFragment {

Communicator callback;

public interface Communicator {
    void setI(String name);
}

public static FragmentAlertDialog newInstance(String id, int title, int items) {
    FragmentAlertDialog frag = new FragmentAlertDialog();
    Bundle args = new Bundle();
    args.putString("id", id);
    args.putInt("title", title);
    args.putInt("items", items);
    frag.setArguments(args);
    return frag;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    callback = (Communicator) getTargetFragment();
} …
Run Code Online (Sandbox Code Playgroud)

android interface callback android-fragments android-dialogfragment

5
推荐指数
1
解决办法
7474
查看次数

Angular Material2 在菜单中滑动切换

是否有任何正确的方法<mat-slide-toggle>在菜单内显示滑动切换<mat-menu>

此外,当我点击 Slide-toggle 时,菜单会消失。有什么办法可以防止这种情况发生。

<mat-menu #menuSettings="matMenu">
    <button mat-menu-item>
      <mat-icon>account_circle</mat-icon>
      <span>Dark</span>
      <mat-slide-toggle></mat-slide-toggle>
    </button>
    <button mat-menu-item>
      <mat-icon>face</mat-icon>
      <span>Register now</span>
    </button>
</mat-menu>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

material-design angular

5
推荐指数
1
解决办法
1465
查看次数

Retrofit方法调用可能会产生'java.lang.NullPointerException'

使用Retrofit 2.3.0我在Android Studio中收到以下消息

在此输入图像描述

有关如何删除此IDE错误消息的任何建议.谢谢

android nullpointerexception retrofit

4
推荐指数
1
解决办法
1479
查看次数

Angular2 +路由-可选的路由参数

所以我有这样的路线/category/tech,并/category/tech/new/category/tech/old

他们都用 ItemsComponent

因此,有什么方法可以像在ExpressJS中那样用可选的参数定义这些类型的路由。

router.get('/category/tech/:filter?', (req, res) => ...
Run Code Online (Sandbox Code Playgroud)

(在这里/category/tech/category/tech/xxx都会工作)

还是我必须像这样分别定义它们

{path: 'users', component: ItemsComponent},
{path: 'users/:filter', component: ItemsComponent}
Run Code Online (Sandbox Code Playgroud)

angular-ui-router angular2-routing angular

3
推荐指数
2
解决办法
3026
查看次数