Questions tagged «android»

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

25
com.android.build.transform.api.TransformException
我试图将Google登录集成到我的应用中,并添加了以下库: compile 'com.google.android.gms:play-services-identity:8.1.0' compile 'com.google.android.gms:play-services-plus:8.1.0' 还将其添加到项目构建gradle: classpath 'com.google.gms:google-services:1.4.0-beta3' 还将插件添加到应用程序构建gradle: apply plugin: 'com.google.gms.google-services' 然后添加所需的权限,但是当我尝试运行我的应用程序时,收到此错误: Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0\bin\java.exe'' finished with non-zero exit value 2


3
在Intellij IDEA / Android Studio中使用合并根标签预览布局
假设我们正在开发基于LinearLayout的复合组件。因此,我们创建这样的类: public class SomeView extends LinearLayout { public SomeView(Context context, AttributeSet attrs) { super(context, attrs); setOrientation(LinearLayout.VERTICAL); View.inflate(context, R.layout.somelayout, this); } } 如果将LinearLayout用作的根,则将somelayout.xml具有额外的视图级别,因此我们使用merge标签: <?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Some text" android:textSize="20sp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Some other text"/> </merge> 但是在IDE的“预览”选项卡中,合并始终充当FrameLayout,我们将看到类似的内容: (这是Android Studio,Intellij IDEA也是一样,关于Eclipse我不知道) 预览大大加快了版面的开发速度,令人遗憾的是,即使对于某些版面,失去这么大的帮助。也许有一种方法可以指定,预览应如何解释merge特定布局中的标签?


16
如何在Android上以编程方式启用或禁用GPS?
我知道关于在Android 上 以 编程方式打开/关闭GPS的问题已经讨论了 很多 次,答案始终是相同的: “出于安全/隐私原因,您不能,必须转到位置首选项屏幕,然后让用户启用/禁用它。” 我了解,但是我最近是从市场上购买Tasker的,除此以外,您还可以设置规则以在进入预定应用程序时自动启用GPS并在退出时将其禁用(请参见此处,有关如何执行此操作的教程,它就可以使用!),此应用无法使用固件签名密钥进行签名,因为它可以在许多android版本和不同的设备上使用,甚至不需要扎根。 我想在我的应用程序中执行此操作。当然,我不想破坏用户的隐私,因此我首先会询问用户是否要使用典型的“记住我的决定”复选框自动打开它,如果他回答是,请启用它。 是否有人对Tasker如何实现这一目标有任何想法或线索?
158 android  gps 

12
使用Fragments为Android中的每个选项卡分离后退堆栈
我正在尝试在Android应用中实现导航标签。由于不推荐使用TabActivity和ActivityGroup,因此我想使用Fragments来实现它。 我知道如何为每个选项卡设置一个片段,然后在单击选项卡时切换片段。但是,如何为每个标签设置单独的后置堆栈? 例如,片段A和B将位于选项卡1下,片段C和D将位于选项卡2下。启动应用程序后,将显示片段A并选择选项卡1。然后,可以将片段A替换为片段B。选择选项卡2后,应显示片段C。如果选择了选项卡1,则应该再次显示片段B。此时,应该可以使用后退按钮显示片段A。 同样,在旋转设备时保持每个标签的状态也很重要。 马丁

8
一个活动和所有其他片段
已关闭。这个问题是基于观点的。它当前不接受答案。 想改善这个问题吗?更新问题,以便通过编辑此帖子以事实和引文回答。 6年前关闭。 改善这个问题 我想实现一个屏幕,Activity和所有其他sreens与Fragments和managing all the fragments thru the activity。 这是个好主意吗?我的回答是“ 否”,但我仍然想更清楚地了解这种想法。 这个想法有什么优点和缺点? 注意: 请不要给我有关片段和活动的链接。 编辑: 以下是有关片段和活动的一些信息: 优点: 片段应与活动一起用作子活动。 碎片不是活动的替代品。 片段旨在实现可重用性(需要知道以何种方式可以实现可重用性。)。 片段是编写支持平板电脑和手机的代码的最佳方法。 缺点: 我们需要实现接口以从片段中获取数据。 对于对话,我们必须走很长的路才能显示出来。 如果不考虑使用平板电脑,为什么还要使用碎片?活动和片段之间的开始时间差是多少?


30
Android设备未显示在adb列表中
已关闭。这个问题需要更加集中。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅通过编辑此帖子来关注一个问题。 2年前关闭。 改善这个问题 我有一个使用USB电缆连接到Windows盒的HP Slate 21。设备上已启用USB调试。后加入适当的%SingleAdbInterface%和%CompositeAdbInterface%条目的android_winusb.inf文件,我现在看到的“Android ADB接口”在我的设备管理器。但是,adb devices在命令行上运行不会显示设备。 我还有另一台HP平板电脑7,在的情况下显示的很好adb devices。 我从“设备管理器”中看到的唯一区别是,可以工作的一个名为“ Android Composite ADB接口”,另一个名为“ Android ADB接口”。 还有另一个细微的区别。在winusb.inf文件中,对于Slate 7,我%CompositeAdbInterface%定义了两个条目,但是对于Slate 21,仅%CompositeAdbInterface%定义了一个条目。 我的设置有什么问题?
158 android  adb 

14
Android,从字符串获取资源ID?
我需要将资源ID传递给我的一个类中的方法。它既需要使用引用指向的id,也需要使用字符串。我应该如何最好地做到这一点? 例如: R.drawable.icon 我需要获取它的整数ID,但是我还需要访问字符串“ icon”。 如果我只需要传递给该方法的是“ icon”字符串,那将是更好的选择。

5
如何从资源ID获取资源名称
在我的布局中,我已经定义了这样的内容。 <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Dnt want this text" /> 假设活动中的某些函数向我返回此ID(radioButton的ID)。现在我想从此id 获取此文本radio1。简而言之,我想检索写入的文字radio1android:id="@+id/radio1" 有人可以告诉我这怎么可能吗?
158 android 

8
如何以编程方式创建ColorStateList?
我正在尝试ColorStateList使用此程序创建一个程序: ColorStateList stateList = new ColorStateList(states, colors); 但是我不确定这两个参数是什么。 根据文档: public ColorStateList (int[][] states, int[] colors) 在API级别1中添加 创建一个ColorStateList,它返回从状态到颜色的指定映射。 有人可以解释一下如何创建吗? 二维状态数组的含义是什么?

9
在Android布局的左右边缘对齐文本视图
我正在开始使用Android。我在进行简单的布局时遇到麻烦。 我想使用a 在单个行中放置LinearLayout两个TextViews。一个TextView在左侧,另一个在右侧(类似于CSS中的float:left,float:right)。 这是否可能,或者我需要使用其他ViewGroup或进一步的布局嵌套来完成它吗? 这是我到目前为止的内容: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:padding="10sp"> <TextView android:id="@+id/mytextview1" android:layout_height="wrap_content" android:text="somestringontheleftSomestring" android:layout_width="wrap_content"/> <TextView android:id="@+id/mytextview2" android:layout_height="wrap_content" android:ellipsize="end" android:text="somestringontheright" android:layout_width="wrap_content"/> </LinearLayout>
158 android 

3
AndroidViewModel与ViewModel
随着Android Architecture Components库的引入,引入了几个新类,包括AndroidViewModel和ViewModel。但是,我很难弄清楚这两个类之间的区别。该文档简要描述AndroidViewModel如下: 应用程序上下文感知 ViewModel 我很简短,但是这意味着什么呢?我们什么时候应该选择使用AndroidViewModelover ViewModel,反之亦然?

7
Android:android.content.res.Resources $ NotFoundException:字符串资源ID#0x5
我在运行应用程序时从标题中获得了例外。它的作用是有一个.txt文件,其中包含适用于“ Hangman”游戏的单词,我认为访问该文件时会抛出异常。我的文件cuvinte.txt位于/ assets /中。这是我的代码(我跳过了layout / xml部分,效果很好): public void onCreate() { // all the onCreate() stuff, then this: try { AssetManager am = this.getAssets(); InputStream is = am.open("cuvinte.txt"); InputStreamReader inputStreamReader = new InputStreamReader(is); BufferedReader b = new BufferedReader(inputStreamReader); String rand; while((rand=b.readLine())!=null){ cuvinte.add(rand); } } catch (IOException e) { Toast.makeText(this, "No words …
158 android  string  file 

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.