我正在阅读Kotlin的基础知识,我对Kotlin中的函数fold()和reduce()非常困惑,有人能给我一个区分两者的具体例子吗?
刚开始学习反应原生,
我创建了一个单独的文件flexdemo.js并创建了如下组件:
import React, { Component } from 'react';
import { View } from 'react-native';
export default class FlexibleViews extends Component {
render() {
return (
<View style={{ flex: 1 }}>
<View style={{ flex: 1, backgroundColor: "powderblue" }}> </View>
<View style={{ flex: 2, backgroundColor: "skyblue" }}> </View>
<View style={{ flex: 3, backgroundColor: "steelblue" }}> </View>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
和App.js文件如下:
import React, { Component } from 'react';
import {
AppRegistry,
Platform,
StyleSheet,
Text,
View, Image
} from 'react-native';
// import …Run Code Online (Sandbox Code Playgroud) 我想在其中不断显示小图标status bar,而不显示notification系统托盘上的通知本身.
我尝试使用自定义layout并将根元素的可见性设置为View.GONE,或者View.INVISIBLE,对于两者,系统忽略它.
我也尝试设置根元素的高度,但系统也忽略了这一点.
这是我的代码:
R.layout.custom_notification:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/custom_notification"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/notif_background"
android:orientation="horizontal"
android:baselineAligned="false"/>
Run Code Online (Sandbox Code Playgroud)
并显示以下代码Notification:
NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx);
mBuilder
.setSmallIcon(drawableId)
.setAutoCancel(false)
.setOngoing(true)
.setPriority(Notification.PRIORITY_MAX);
Intent resultIntent = new Intent(ctx, SettingsActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(ctx, 0, resultIntent, 0);
mBuilder.setContentIntent(resultPendingIntent);
int layout = R.layout.custom_notification ;
RemoteViews contentView = new RemoteViews(ctx.getPackageName(), layout);
contentView.setViewVisibility(R.id.custom_notification, View.INVISIBLE);
mBuilder.setContent(contentView);
nm.notify(NOTIFICATION_ID, mBuilder.build());
Run Code Online (Sandbox Code Playgroud)
我很清楚,为了实现我的目标,我不需要记录解决方案.而且我也知道UX准则强烈建议不做这样的事情.所以没有必要把这个作为答案写给我.
我的问题是,每次我选择第三方相机应用程序,例如Beauty Plus Camera我每次都有空指针异常,我的代码完全适用于默认的相机应用程序,它甚至可以与谷歌为摩托车系列手机制作的新相机配合使用.
第一次选择画廊或相机选项的对话框如下:
private void OpenDialogForImage() {
final CharSequence[] items = {
"Gallary", "Camera", "Cancel"
};
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Do something with the selection
switch (item) {
case 0:
Intent intent1 = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent1.setType("image/*");
startActivityForResult(
Intent.createChooser(intent1, "Select File"),
SELECT_FILE);
break;
case 1:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
break;
case 2:
break;
}
}
});
AlertDialog alert = builder.create(); …Run Code Online (Sandbox Code Playgroud) camera android nullpointerexception android-intent android-camera-intent
有人可以给我具体的hashMapOf()方法示例,我应该何时使用它?
如果我做这样的事情:
val map2 : HashMap<String, String> = hashMapOf()
map2["ok"] = "yes"
Run Code Online (Sandbox Code Playgroud)
这意味着初始化map2属性我可以使用它.
但是像Kotlin中的其他方法一样:
val arr = arrayListOf<String>("1", "2", "3")
Run Code Online (Sandbox Code Playgroud)
我有什么方法可以像上面那样使用这种方法吗?
目前是android开发的初学者,我一直在关注一些练习/教程,我遇到的问题是RecyclerView中的项目之间的距离太远,如下图所示.如何让它更接近彼此?我一直在寻找,但没有任何作用.
编辑:更改android:layout_height = "match_parent"为后android:layout_height = "wrap_content"仍然没有更改布局.
所以我把我的java课程包括在内
这是我的 .xml
custom_row_news_items.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/date_text"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
<ImageView
android:src="@drawable/img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/thumb_img"
android:layout_below="@+id/date_text"
android:layout_centerHorizontal="true" />
<TextView
android:background="#006699"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/title_text"
android:layout_alignBottom="@+id/thumb_img"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/des_text"
android:layout_below="@+id/thumb_img"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
content_navigation_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_navigation_drawer"
tools:context="com.example.azrie.dummyvoicethenews.NavigationDrawer">
<android.support.v7.widget.RecyclerView …Run Code Online (Sandbox Code Playgroud) 从此处开始使用导航架构时,不推荐使用此处的clearTask。
我的场景是这样的:有 2 个屏幕登录和注册,两者都有彼此的链接。所以你可以从登录进入注册,也可以从注册登录。但在后面 Press App 应该关闭。
只需将 clearTask 添加到以下两个操作即可轻松完成。
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/nv_auth_phase"
app:startDestination="@id/fragment_login">
<fragment
android:id="@+id/fragment_login"
android:name="com.jobhook.ui.auth.login.LoginFragment"
android:label="LoginFragment"
tools:layout="@layout/fragment_login">
<action
android:id="@+id/nv_action_login_to_registration"
app:clearTask="true"
app:destination="@id/fragment_registration" />
</fragment>
<fragment
android:id="@+id/fragment_registration"
android:name="com.jobhook.ui.auth.registration.RegistrationFragment"
android:label="RegistrationFragment"
tools:layout="@layout/fragment_registration">
<action
android:id="@+id/nv_action_registration_to_login"
app:clearTask="true"
app:destination="@id/fragment_login" />
</fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)
但是由于它已被弃用,我尝试了其他解决方案,例如添加popUpTo -> 导航图的 Id,使两个操作中的 launchSingleTop 都为 true。在我的场景中似乎没有任何效果。
我也检查了这个问题,但没有得到解决方案。
android android-fragments android-architecture-components android-architecture-navigation
我是Firebase的新用户,我正在尝试将Firebase Auth api连接到我的应用程序中,我已经关注了来自官方网站的更新文档的文档,所有工作都正常.
我已经成功完成了SignIn,在我的仪表板中,我登录后获得了所有用户.
我的问题是我对从Firebase返回的各种ID感到困惑
代码如下:
for (UserInfo profile : user.getProviderData()) {
// Id of the provider (ex: google.com)
String providerId = profile.getProviderId();
//if Id of the provider is firebase it means we have successfully get back data after saving in firebbase hence we continue to app
if(providerId.equals("firebase")) {
// UID specific to the provider
Other.SavePref(this, "LoginToken", profile.getUid());
// Name, email address, and profile photo Url
String name = profile.getDisplayName();
String email = profile.getEmail();
Uri photoUrl = profile.getPhotoUrl(); …Run Code Online (Sandbox Code Playgroud) 我是 Android 数据绑定概念的新手,我已经从这个博客中阅读了它,并且它与他们提供的简单示例一起正常工作,我进行了一个空白活动,因此将有两个文件activity_main.xml,content_main.xml
这是activity_main.xml代码
<android.support.design.widget.CoordinatorLayout
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/stat_notify_sync_noanim" />
</android.support.design.widget.CoordinatorLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
正如我所建议的那样,我已经将父级作为布局,并且从 Java 端我按如下方式访问它
public class MainActivity extends AppCompatActivity {
ActivityMainBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
setSupportActionBar(activityMainBinding.toolbar);
//Floating Action Button
activityMainBinding.fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with …Run Code Online (Sandbox Code Playgroud) 在Android Studio中,右下角有处理分支的选项。在合并另一个远程或本地分支的“合并”选项中,它显示诸如Force merge和的选项smart merge。
他们到底在做什么?
与本地/远程分支机构合并时?
我想存储键值对< 4.1, 29..35 >,我可以用它来做HashMap<Double, Range<Int>>:
val womanMap: HashMap<Double, Range<Int>> = hashMapOf()
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun createMap() {
//This both requires API 21
val range = Range(29,35)
womanMap[4.6] = Range.create(29,35)
}
Run Code Online (Sandbox Code Playgroud)
如何在API级别21下执行此操作?
android ×9
kotlin ×3
android-architecture-components ×1
android-architecture-navigation ×1
camera ×1
data-binding ×1
firebase ×1
fold ×1
git ×1
git-merge ×1
hashmap ×1
react-native ×1
reduce ×1