Questions tagged «android»

Android是Google的移动操作系统,用于对数字设备(智能手机,平板电脑,汽车,电视,Wear,Glass和IoT)进行编程或开发。对于与Android相关的主题,请使用特定于Android的标签,例如android-intent,android-activity,android-adapter等。对于与开发或编程无关但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。

5
如何为不同的gradle buildTypes提供不同的Android应用程序图标?
我的gradle文件中设置了两种构建类型:debug和release。我希望能够为debug构建类型设置其他应用程序图标。有没有办法通过构建类型来实现此目的,而又不涉及产品风味?build.gradle文件在下面。 apply plugin: 'android' //... android { compileSdkVersion 19 buildToolsVersion "19.0.3" defaultConfig { minSdkVersion 14 targetSdkVersion 19 versionCode 30 versionName "2.0" } buildTypes { debug { packageNameSuffix '.debug' versionNameSuffix '-SNAPSHOT' } release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) }
99 android  gradle 

10
弹出软键盘时页面滚动
我有一个<ScrollView>布局: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/my_scrollview" android:layout_width="fill_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <EditText android:id="@+id/input_one" android:layout_width="300dp" android:layout_height="wrap_content" android:layout_gravity="center" android:inputType="number" > <EditText android:id="@+id/input_two" android:layout_width="300dp" android:layout_height="wrap_content" android:layout_gravity="center" android:inputType="number" > <EditText android:id="@+id/input_three" android:layout_width="300dp" android:layout_height="wrap_content" android:layout_gravity="center" android:inputType="number" > <Button android:id="@+id/ok_btn" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="20dp" android:text="@string/ok_str" /> </LinearLayout> </ScrollView> 如上所示,简单的布局包括三个输入字段和一个“确定”按钮。 我以上述布局运行我的应用程序,当我点击第一个输入字段(@+id/input_one)时,软键盘将从屏幕底部弹出,它隐藏了第三个输入字段和“确定”按钮。 自从我使用以来<ScrollView>,我想可以向上滚动页面以查看软键盘隐藏的第三个输入字段和“确定”按钮,但是该页面不可滚动。为什么?如何摆脱它?基本上,我希望看到每个输入字段和“确定”按钮,甚至弹出的软键盘也是如此。

13
如何从URI获取完整文件路径
我想从URI获取完整的文件路径。URI不是图像,而是音乐文件,但是如果我像MediaStore解决方案那样操作,则如果应用程序用户选择例如Astro作为浏览器而不是Music Player,它将无法正常工作。我该如何解决?
99 android  path  get  uri 

1
Android中的runOnUiThread vs Looper.getMainLooper()。post
谁能告诉我使用runOnUiThread()与Looper.getMainLooper()。post()在Android的UI线程上执行任务之间是否有区别? 我唯一能确定的是,由于runOnUiThread是非静态的Activity方法,因此当您需要在无法看到Activity的类中编写某些代码时,Looper.getMainLooper()。post()更方便。接口)。 我不希望在UI线程上执行某些操作的讨论中,我发现有些事情不能执行,很多事情不应该执行,但是某些事情(例如启动AsyncTask)必须从以下位置执行UI线程。 谢谢, R。

8
“已经存在的程序类型”是什么意思?
我正在尝试在Android Studio中构建应用。在将Eclipse Paho库添加为gradle依赖项之后(或者它是Maven?我是Android生态系统的新手),出现以下错误: Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat Message{kind=ERROR, text=Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat, sources=[Unknown source file], tool name=Optional.of(D8)} 我检查了许多与此错误有关的StackOverflow问题,但是答案都是特定于某些库的。 我不仅在寻找错误的解决方案,而且还在寻找错误的含义。 这样,人们可以更轻松地找到针对其特定情况的解决方案。到目前为止,还没有答案。 从其他StackOverflow答案中,我收集到它与gradle文件有关。因此,这是app / build.gradle: apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId "---REDACTED FOR PRIVACY---" minSdkVersion 15 targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes …


3
通过ClipData.Item.getUri在应用程序之外公开
我尝试在Android文件系统中添加新功能后解决问题,但出现此错误: android.os.FileUriExposedException: file:///storage/emulated/0/MyApp/Camera_20180105_172234.jpg exposed beyond app through ClipData.Item.getUri() 所以我希望有人可以帮助我解决这个问题:) 谢谢 private Uri getTempUri() { // Create an image file name SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss"); String dt = sdf.format(new Date()); imageFile = null; imageFile = new File(Environment.getExternalStorageDirectory() + "/MyApp/", "Camera_" + dt + ".jpg"); AppLog.Log( TAG, "New Camera Image Path:- …
99 java  android 

10
如何在logcat中显示长消息
我正在尝试在logcat上显示长消息。如果消息的长度超过1000个字符,它将被打断。 在logcat中显示长消息的所有字符的机制是什么?
99 android  logcat 

9
给定的工件包含一个字符串文字,其字符串包参考'android.support.v4.content'无法安全地重写。对于androidx
我升级了我的软件android studio to 3.4 canary,由于以下错误,我现在无法成功构建: The given artifact contains a string literal with a package reference 'android.support.v4.content' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx. 更多细节: Caused by: java.lang.RuntimeException: Failed to transform '.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/9.0.0-SNAPSHOT/732f93940c74cf32a7c5ddcc5ef66e53be052352/butterknife-compiler-9.0.0-SNAPSHOT.jar' using Jetifier. Reason: …

9
拒绝加载脚本,因为它违反了以下内容安全策略指令
当我尝试将应用程序部署到5.0.0(Lollipop)以上的Android系统的设备上时,我不断收到以下错误消息: 07-03 18:39:21.621:D / SystemWebChromeClient(9132):file:///android_asset/www/index.html:第0行:拒绝加载脚本“ http:// xxxxx”,因为它违反了以下内容安全策略指令:“ script-src'self''unsafe-eval''unsafe-inline'”。07-03 18:39:21.621:I / chromium(9132):[INFO:CONSOLE(0)]“拒绝加载脚本'http:// xxx',因为它违反了以下内容安全策略指令:” script- src'self''unsafe-eval''unsafe-inline'“。 但是,如果我将其部署到Android系统为4.4.x(KitKat)的移动设备上,则安全策略可与默认策略一起使用: <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> 然后我想,也许我应该改成这样: <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-eval' 'unsafe-inline'; object-src 'self'; style-src 'self' 'unsafe-inline'; media-src *"> 基本上,这两个选项都不适合我。我该如何解决这个问题?

17
如何在Android中更改工具栏后退按钮的颜色?
我无法更改后退按钮的颜色。我正在使用工具栏材质设计。在我的应用程序中,我正在使用工具栏的黑色背景,但是默认情况下后盖的设计为黑色,这就是为什么我只想更改此后盖按钮的颜色的原因。请给我解决方案。 谢谢
99 android 

7
约束布局垂直对齐中心
如何在约束布局中垂直对齐和居中对象?可以垂直或水平对齐,但是除了约束两条网格线之间的视图外,我还没有找到一种同时居中的方法。 垂直对齐中心: 居中似乎是约束布局的一个巨大问题,它迫使我回到“ centerInParent”,“ centerVertical”和“ centerHorizo​​ntal”的相对布局。 我想使用约束布局创建以红色框出的布局: 不幸的是,我发现不使用两条网格线的唯一方法是使用嵌套的Relative和LinearLayouts(应该使用约束布局来解决这种确切的情况!)。 使用相对和线性布局的布局: <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="12dp" app:layout_constraintTop_toBottomOf="@id/user_points" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent"> <LinearLayout android:id="@+id/stat_1_layout" android:layout_width="60dp" android:layout_height="wrap_content" android:layout_marginLeft="12dp" android:layout_marginRight="12dp" android:layout_centerVertical="true" android:layout_toLeftOf="@+id/divider_1" android:orientation="vertical"> <TextView android:id="@+id/stat_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:gravity="center_horizontal" android:text="10" android:textSize="16dp" android:textColor="@color/textSecondaryDark" android:maxLines="1"/> <TextView android:id="@+id/stat_detail_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:gravity="center" android:text="Streak" android:textSize="8sp" android:textColor="@color/textSecondary" android:maxLines="1"/> </LinearLayout> <View android:id="@+id/divider_1" android:layout_width="1dp" android:layout_height="38dp" …

11
无法解析主机“ <在此处插入URL>”没有与主机名关联的地址
我尝试按照本教程进行操作: 从Web获取数据 我尝试在最新的平板电脑平台Android 3.0上实现它,但是,出现此错误:“ 无法解析主机“ www.anddev.org”没有与主机名相关联的地址。 “ 您可以检出我只是用来证明文件存在的URL。 http://www.anddev.org/images/tut/basic/getdatafromtheweb/loadme.txt 我创建了一个私有类,并使用asynctask对其进行了扩展。这是代码: private class Downloader extends AsyncTask&lt;String,Void,String&gt;{ String myString = null; @Override protected String doInBackground(String... arg0) { try{ URL myURL = new URL("http://www.anddev.org/images/tut/basic/getdatafromtheweb/loadme.txt"); URLConnection ucon = myURL.openConnection(); InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int …

8
如何向活动finish()添加动画
我在创建活动时使用了overridePendingTransition,并且效果很好,我可以看到淡入效果很好,但是当我尝试对活动的结束进行动画处理时,它仍在执行默认的从右到左滑动。 开始活动时,我首先尝试定义out动画,如下所示: Intent myIntent = new Intent(a, SkdyAlert.class); myIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); a.startActivity(myIntent); if (android.os.Build.VERSION.SDK_INT &gt; android.os.Build.VERSION_CODES.DONUT) { AnimationHelper.overridePendingTransition(a, R.anim.fadein, R.anim.fadeout); } 然后我在完成活动时也尝试这样做 okBtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); if (android.os.Build.VERSION.SDK_INT &gt; android.os.Build.VERSION_CODES.DONUT) { AnimationHelper.overridePendingTransition(activity, 0, R.anim.fadeout); } } }); 但是,这两种方法都不会阻止退出动画从右向左滑动。关于我在做什么错的任何想法吗?


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.