我已经设置了以下路由系统
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)
示例网址如下所示
有时他们有可选的 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) 我已经在我的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
我想创建一个简单的(是/否)对话框首选项,我按照这篇文章中的答案 - 从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 & 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
我使用以下布局(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) 我试图将一些数据从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
是否有任何正确的方法<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)
所以我有这样的路线/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)