我有一个Composable带有 lambda 的函数,用于获取按钮单击操作。我想预览一下这个Composable功能。但是使用这种 lambda 的可组合函数在添加@Preview上面的注释后会出现错误@Composable
Composable functions with non-default parameters are not supported in Preview unless they are annotated with @PreviewParameter.
可组合函数看起来像
@Composable
fun MyView(onViewButtonClick: () -> Unit) {
Button(
enabled = isEnabled, colors = ButtonDefaults.buttonColors(
backgroundColor = greenColor
),
shape = Shapes.large, onClick = (onViewButtonClick),
modifier = Modifier
.fillMaxWidth()
.padding(15.dp, 40.dp, 15.dp, 15.dp)
) {
Text(
text = stringResource(id = R.string.send_otp),
color = Color.White,
fontSize = 20.sp
)
}
}
Run Code Online (Sandbox Code Playgroud)
这个的应用看起来像
MyView(onViewButtonClick …Run Code Online (Sandbox Code Playgroud) android higher-order-functions kotlin android-jetpack android-jetpack-compose
Dynamic Link我在 Firebase 控制台中创建了一个。我在应用程序中有“引用”选项,它创建一个动态链接,并且该链接通过某些媒体共享。根据 Firebase 文档,如果尚未安装应用程序,它将打开 Play 商店并允许用户下载该应用程序。但是,一旦下载了应用程序(根据文档),它应该显示Continue首次打开应用程序的选项,以便预期的动态链接流将起作用。但我还没有从 Play 商店收到这样的“首次安装”选项,它显示了Open破坏动态链接并从头开始打开应用程序的选项。
生成的代码Dynamic Link是
String e="https://myappinvite.page.link/?link=https://myappinvite.page.link/?referid=10&apn=com.learnandro&amv=16&st=Please Install the App&si="+some Image Url+"&afl=https://play.google.com/store/apps/details?id=app Package name";
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance()
.createDynamicLink()
.setLongLink(Uri.parse(e))
.buildShortDynamicLink()
.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
@Override
public void onComplete(@NonNull Task<ShortDynamicLink> task) {
Uri get=task.getResult().getShortLink();
Intent sh=new Intent(Intent.ACTION_SEND);
sh.setType("text/plain");
sh.putExtra(Intent.EXTRA_TEXT,"Vi ew the Amazing Event "+get);
startActivity(Intent.createChooser(sh,"View"));
}
});
Run Code Online (Sandbox Code Playgroud)
该Manifest文件看起来像这样
<activity android:name=".login.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category …Run Code Online (Sandbox Code Playgroud) 当我的应用程序打开时,首先显示主屏幕。NavigationDrawer在主屏幕上,我在按下后打开了它。后来HamburgerIcon我转到不同的片段。当我在除 Home 之外的其他片段中时,Activity我需要显示后退按钮Toolbar才能回到上一个片段。但它每次都显示汉堡图标。如何做到这一点?
这是Toolbar在 XML 中设置的代码
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawerLayout"
tools:context="biz.fyra.myApp.ActivityTwo">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ccc"
android:minHeight="?attr/actionBarSize">
<ImageView
android:id="@+id/tooImage"
android:src="@drawable/latest"
android:layout_width="match_parent"
android:layout_gravity="center_horizontal"
android:layout_height="40dp" />
</android.support.v7.widget.Toolbar>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame">
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
android:id="@+id/navigationView"
app:menu="@menu/actionmenu"
android:background="@android:color/white">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
如何实现这一目标?
android android-fragments navigation-drawer android-toolbar hamburger-menu
我ArchitectureComponents在我的应用程序中使用。我正在使用 ActivityMain 中的 ViewModel发出API请求ViewModel并将数据设置为RecyclerView使用 ViewModel。为了进行 Api 调用,我需要一个Token保存在SharedPreference.I 中的令牌。我需要获取该令牌并将其添加到标题中,同时发出请求。哪里以及如何获取 SharedPreference 值。它应该在 ViewModel 或 Repository 中。
这是我的代码ViewModel
public class FoodieViewModel extends AndroidViewModel {
FoodieRepository repository;
MutableLiveData<ArrayList<Foodie>> foodieList;
public FoodieViewModel(@NonNull Application application) {
super(application);
repository=new FoodieRepository(application);
}
LiveData<ArrayList<Foodie>> getAllFoodie(){
if(foodieList==null){
foodieList=new MutableLiveData<ArrayList<Foodie>>();
loadFoodies();
}
return foodieList;
}
public void loadFoodies(){
String url="somethimg.com";
JsonArrayRequest request =new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
ArrayList<Foodie> list=new ArrayList<>(); …Run Code Online (Sandbox Code Playgroud) android sharedpreferences android-recyclerview android-architecture-components
我正在我的.IRecyclerview中使用我的 RecyclerView 类。我需要在我编写的一种方法中显示。但我收到一个错误FragmentAdapterAlertDialogAdapterClass
android.app.Activity 无法应用于 android.content.Context。
这是我的代码AlertClass
public class AlertClass {
public void noInternetAlert(Activity activity)
{
final AlertDialog alertDialog=new AlertDialog.Builder(activity).create();
AlertDialog.Builder builder=new AlertDialog.Builder(activity);
builder.setTitle("No Internet Connection");
builder.setMessage("You need to have Mobile data or Wifi to access this.");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
alertDialog.cancel();
}
});
builder.show();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的方法的代码AdapterClass
private void free() {
AlertClass alert=new AlertClass();
alert.noInternetAlert(context);
}
Run Code Online (Sandbox Code Playgroud)
这是适配器类的代码
public class BusyAdapter extends RecyclerView.Adapter<BusyAdapter.ViewHolder>
{ …Run Code Online (Sandbox Code Playgroud) android android-context android-fragments android-dialog android-recyclerview
我正在Room使用ViewModel. 一切都运转良好。但要求是我想提供一些对ViewModel使用的依赖AndroidViewModelFactory。我能够创建ViewModelFactory实现ViewModelProvider.Factory. 我将一个普通字符串作为 ViewModel 的依赖项传递。工厂类的代码是
public class TestViewModelFactory implements ViewModelProvider.Factory{
private static final String DEFAULT_LIMIT = "4";
static Application application;
static String created="ViewModelFactorySuccess";
public static TestViewModelFactory createFactory(Activity activity) {
application = activity.getApplication();
if (application == null) {
throw new IllegalStateException("Not yet attached to Application");
}
return new TestViewModelFactory(application, created);
}
public TestViewModelFactory(Application application, String created) {
application=application;
created=created;
}
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> …Run Code Online (Sandbox Code Playgroud) android ×7
android-architecture-components ×1
android-mvvm ×1
bottombar ×1
deep-linking ×1
firebase ×1
kotlin ×1
mvvm ×1