小编Rea*_*hed的帖子

Android 弹出窗口与 Android 对话框

我试图在我的应用程序中实现一个简单的逻辑,其中向用户显示一个弹出窗口(在应用程序启动一段时间后)。弹出窗口只显示TextView带有一些信息的消息。每次启动应用程序时都会刷新此消息并显示一条新消息。弹出窗口的 UI 与我的应用程序 UI 匹配 - 这里可能只需要弹出背景图像。还有一个关闭按钮 (X) 显示在弹出窗口的右上角 - 关闭此弹出窗口。

显示消息的逻辑:我有一个String数组,其中存储了大约 100 个字符串。我从这个数组中随机选择一个字符串并填充TextView显示消息的弹出窗口。请建议是否有比我已经在这里做的更好的方法。是否也有可能逻辑,如果选择了一条消息,那么在其他消息至少显示一次之前不会选择相同的消息?

显示弹出窗口的逻辑:这是我无法实现的。我不想用任何用户EventButton点击来锚定弹出窗口。我只是想在一段时间后显示消息 - 说

线程睡眠(3000);

现在我尝试使用PopupWindow下面的代码来使用它。

PopupWindow infoPopup;    
LinearLayout infoLayout;
TextView infoTextView;
Button infoButton;
infoTextView = new TextView(this);
infoTextView.setText("Testing Popup Text");
infoTextView.setPadding(10,10,10,10);
infoButton = new Button(this);
infoButton.setText("Close");    
infoLayout = new LinearLayout(this);
infoLayout.setOrientation(LinearLayout.VERTICAL);
infoLayout.addView(infoTextView);
infoLayout.addView(infoButton);    
infoPopup = new PopupWindow(infoLayout,LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
infoPopup.setContentView(infoLayout);    
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}    
infoPopup.showAtLocation((CoordinatorLayout)findViewById(R.id.main_content),Gravity.CENTER,100,100);
Run Code Online (Sandbox Code Playgroud)

但是这个弹出窗口在最后一行显示错误,在我的

(CoordinatorLayout)findViewById(R.id.main_content)

范围。 …

java android popupwindow android-alertdialog

3
推荐指数
1
解决办法
5281
查看次数

可以用字符串获得颜色?

在我的values文件夹中,我有my_colors.xml:

<resources>
    <!-- Orange -->
    <color name="orangePrimary">#f6a02d</color>
    <color name="orange1">#e3952a</color>
    <color name="orange2">#da8f28</color>
    <color name="orange3">#d08926</color>
</resources>
Run Code Online (Sandbox Code Playgroud)

有没有办法让这些颜色只是用它的名字串?就像是view.setBackgroundColor.getColor("orange1");

对于图像,你有这个 getResources().getIdentifier("my_image", "drawable", getPackageName());

希望你们知道我的意思.问候.

string android colors android-resources

3
推荐指数
1
解决办法
2753
查看次数

在 SharedPreferences 中保存字符串集的最快方法是什么?

我有 2 个数据集

String[] wordsArray;
Queue<String> wordsQueue;
Run Code Online (Sandbox Code Playgroud)

它们存储相同的数据,每个大约 500 个字符串,每个字符串 1-3 个单词。我需要将其中之一保存到SharedPreference. 最好(最快)的方法是什么?

现在我只用

Set<String> mySet = new HashSet<String>(wordsQueue);
edit.putStringSet("Words", mySet);
Run Code Online (Sandbox Code Playgroud)

但它的工作速度比我想要的要慢。

java android sharedpreferences

3
推荐指数
1
解决办法
1394
查看次数

ScrollView中的RecyclerView wrap_content高度未按预期工作

我有一个RecyclerView嵌入式ScrollView.这是完整的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_height="wrap_content">

            <fragment
                android:name="devarshi.sample.view.ProductPortfolioFragment"
                android:id="@+id/fragmentProductPortfolio"
                android:layout_width="match_parent"
                android:layout_margin="10dp"
                android:layout_height="230dp" />

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:text="TextView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/textViewProductName" />

                <TextView
                    android:text="TextView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/textViewProductDescription" />

                <LinearLayout
                    android:id="@+id/linearLayoutProductDetails"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:text="@string/product_detail_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/textViewProductDetails" />
                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:id="@+id/linearyLayoutOtherProductDetails"
                android:layout_height="100dp">

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="0dp"
                    android:layout_weight="0.6"
                    android:layout_height="wrap_content">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:orientation="horizontal"
                        android:id="@+id/linearLayoutPrice"
                        android:layout_height="wrap_content">

                        <TextView
                            android:id="@+id/textViewProductPrice"
                            android:layout_width="wrap_content"
                            android:textSize="15sp"
                            android:textStyle="bold"
                            android:textColor="@color/colorDiscountedPrice" …
Run Code Online (Sandbox Code Playgroud)

java android android-scrollview android-recyclerview

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

在Android Studio中搭建android应用的开发和生产环境

我有两个关于这个问题的问题。

  1. 如果在 laravel/web 中我们有.env文件将环境设置为“开发”或生产并自动连接到不同的数据库。在 android/kotlin/android studio 怎么样?

  2. 以及如何在 PC 上向我的本地主机(127.0.2.1)发出我的应用程序请求(如果它在“开发”环境中)以及如何向真实的 url API 发出请求(如果它在“生产”环境中)。仅供参考,我不使用模拟器。我用我的手机来测试我的应用程序。

android kotlin android-studio android-gradle-plugin

3
推荐指数
1
解决办法
2910
查看次数

更新SQLite表而不丢失android中的先前数据

我正在尝试在旧的sqlite数据库表中添加新列。这些表是动态的。我的意思是,它们是在应用程序用户在应用程序中添加特定数据时创建的。

表名称具有类似的后缀。前缀取决于用户输入。现在,在android中,如何在不丢失先前数据的情况下在这些表中添加新列?

java sqlite android sqliteopenhelper

3
推荐指数
1
解决办法
968
查看次数

如何在Android上使用AudioTrack.getTimestamp()来计算延迟?

我看到许多资源建议AudioTrack.getTimestamp()在现代 Android 版本上使用来计算音频/视频同步的音频延迟。

例如:

/sf/answers/2633805401/

https://developer.amazon.com/docs/fire-tv/audio-video-synchronization.html#section1-1

https://groups.google.com/forum/#!topic/android-platform/PoHfyNK54ps

但是,这些都没有解释如何使用时间戳来计算延迟?我正在努力弄清楚如何处理时间戳的framePosition/nanoTime 来得出延迟数字。

audio android audiotrack

3
推荐指数
1
解决办法
2162
查看次数

如何防止使用导航控制器按“后退”按钮后显示先前的片段?

我正在尝试使用导航控制器。我想从LoginFragment移至HomeFragment。在LoginFragment此,我使用下面的代码移至HomeFragment

Navigation.findNavController(view).navigate(homeDestination)
Run Code Online (Sandbox Code Playgroud)

但是,当我点击中的后退按钮时HomeFragment,它将返回到LoginFragment,我希望当我点击按钮时它将关闭该应用程序。

以旧的方式,如果我使用activity而不是using Fragment,那么我通常会执行以下操作来获得预期的行为:

val intent = Intent(this,HomeActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK.or(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
Run Code Online (Sandbox Code Playgroud)

通过使用这些标志,我可以用来获得预期的行为。但是我不使用导航控制器来实现相同的行为。

android kotlin android-navigation android-jetpack android-architecture-navigation

3
推荐指数
1
解决办法
1389
查看次数

android studio 3.4 中的 R.java 文件

我只是想学习 android 开发,并且正在使用最新版本的 android studio,但是,我在R.java文件夹树视图中找不到该文件:

在此处输入图片说明

我还清理并重建了我的项目,但仍然看不到.../source/R文件夹和R.java文件。

android r.java-file android-studio

3
推荐指数
1
解决办法
3169
查看次数

如何找出平板电脑支持的采样率?

我有一个应用程序在一堆设备(Xoom,Xyboard等)上完美运行但在Galaxy 10.1上的这一行失败了

mrec.setAudioSamplingRate(44100);
Run Code Online (Sandbox Code Playgroud)

当我评论这条线时,一切都在游泳.(我不确定它默认使用的速率).我的猜测是该设备不支持这种特定的采样率,但我没有在文档中看到任何可以查找对象的方法,以找出支持的采样率.

所有帮助赞赏.

java android audio-recording

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