Questions tagged «android»

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


10
无法从活动中调用getSupportFragmentManager()
我有一个有片段的活动。 XML: <fragment android:name="com.example.androidcalculator.ResultFragment" android:id="@+id/result_fragment" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content" /> 而且我想从Activity中的方法中调用ResultFragment中的方法,但是getSupportFragmentManager“不存在”: FragmentManager fragMan = getSupportFragmentManager(); 我该如何解决?

4
为什么棒棒糖上的CardViews之间没有空间?
我尝试使用,CardView并且它在5.0以下都可以正常工作,但是在Lollipop上看起来很奇怪。 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="200dp"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="card1" android:textAppearance="?android:attr/textAppearanceLarge" /> </android.support.v7.widget.CardView> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="200dp"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="card2" android:textAppearance="?android:attr/textAppearanceLarge" /> </android.support.v7.widget.CardView> </LinearLayout> 使用时,我遇到相同的问题RecyclerView,如果它在Lollipop上运行,是否应该添加一些内容?

5
转换为Dalvik格式失败:无法执行dex:Java堆空间
我已将2.45mb jar文件添加到我的Android eclipse项目中,现在无论我做什么,我都继续收到“转换为Dalvik格式失败:无法执行dex:Java堆空间”的信息。 我在网上进行了研究,并被告知要更新eclipse.ini以增加Java VM的堆大小。我已经为eclipse.ini中的所有值完成了此操作,并且继续出现构建错误。 有任何想法吗?
79 java  android  eclipse 

12
Gradle Build Android Project“无法解决所有依赖性”错误
我正在尝试使用Gradle构建我的第一个项目,我认为gradle文件和设置正确。 我仅使用一个模块并支持V4 + AppCompatBar库。 项目-build.gradle allprojects { repositories { mavenCentral() } } 项目-settings.gradle include ':AssignmentTempos21' 主模块-build.gradle buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 17 buildToolsVersion "17.0.0" defaultConfig { minSdkVersion 8 targetSdkVersion 17 } } dependencies …

12
使用Android SDK发布多部分请求
我正在尝试做一些我认为相对简单的事情:使用Android SDK将图像上传到服务器。我发现了很多示例代码: http://groups.google.com/group/android-developers/browse_thread/thread/f9e17bbaf50c5fc/46145fcacd450e48 http://linklens.blogspot.com/2009/06/android-multipart-upload.html 但是对我都不起作用。我一直遇到的困惑是发出多部分请求的真正需要。在Android上进行分段上传(带有图片)的最简单方法是什么? 任何帮助或建议,将不胜感激!


3
更改棒棒糖上的通知图标背景
我正在经历 通知”设计模式,但没有发现任何有关通知图标背景的内容。您可能已经注意到,自定义通知只有浅灰色的背景。但是环聊或简单的USB调试通知等应用的通知图标背景具有自定义颜色。 是否有可能将灰色更改为其他颜色?(以编程方式指定特定圆圈的颜色)

11
自动折叠ActionBar SearchView在软键盘上关闭
我目前正在使用ActionBar菜单项在操作栏中显示SearchView。展开搜索菜单项后,将显示我想要的软键盘。现在,当用户按下后退按钮以关闭软键盘时,我也想在操作栏中折叠SearchView。 我已经尝试在MenuItem和ActionView上实现以下侦听器OnKeyListener和OnFocusChangeListener。我也尝试在Activity中使用OnBackPressed()。当使用后退按钮关闭软键盘时,以上方法均无法检测。 有任何想法吗? 我已经实现了OnActionExpandListener,以知道何时可以看到SearchView。

14
使用try / catch防止应用崩溃
我一直在开发一个Android应用程序,该应用程序try/catch经常使用以防止它崩溃,即使在不需要的地方也是如此。例如, 在视图xml layout与id = toolbar被引用,如: // see new example below, this one is just confusing // it seems like I am asking about empty try/catch try { View view = findViewById(R.id.toolbar); } catch(Exception e) { } 在整个应用程序中都使用这种方法。堆栈跟踪没有打印出来,很难找到问题所在。该应用程序突然关闭,而不打印任何堆栈跟踪。 我请我的长辈向我解释一下,他说: 这是为了防止生产崩溃。 我完全不同意。对我来说,这不是防止应用程序崩溃的方法。它表明开发人员不知道自己在做什么,并且对此表示怀疑。 这是行业中用来防止企业应用程序崩溃的方法吗? 如果try/catch确实是我们的真正需求,那么是否可以将异常处理程序与UI线程或其他线程连接,并在那里捕获所有内容?如果可能的话,那将是一个更好的方法。 是的,为空try/catch很不好,即使我们将堆栈跟踪或日志异常打印到服务器,try/catch对我来说,将代码块随机地包装在所有应用程序中也没有意义,例如,将每个函数都包含在try/catch。 更新 由于这个问题引起了广泛关注,并且有些人误解了这个问题(也许是因为我没有清楚地表述),所以我将其重新表述。 这是开发人员在这里所做的 一个函数是经过编写和测试的,它可以是一个仅初始化视图的小函数,也可以是一个复杂的函数,在测试后将其包裹在try/catch块中。即使对于永远不会抛出任何异常的函数。 在整个应用程序中都使用了这种做法。有时打印堆栈跟踪,有时只是打印debug log一些随机错误消息。此错误消息因开发人员而异。 通过这种方法,应用程序不会崩溃,但是应用程序的行为无法确定。即使在某个时候,也很难跟踪出了什么问题。 …

13
错误:包com.android.annotations不存在
我有以下课程 import com.android.annotations.NonNullByDefault; @NonNullByDefault public final class Log { ... } 这是我的build.gradle文件(一些部分省略了) apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion '24.0.1' defaultConfig { minSdkVersion 16 targetSdkVersion 25 versionCode 2 versionName "0.2" } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } } dependencies { compile 'com.android.support:appcompat-v7:25.0.0' compile 'com.android.support:support-annotations:25.0.0' compile 'com.android.support:design:25.0.0' } 在Android …

3
在Android上处理Google Cloud Messaging中的注册ID更改
在Google Cloud Messaging的文档中,它指出: Android应用程序应存储此ID供以后使用(例如,检查onCreate()是否已注册)。请注意,Google可能会定期刷新注册ID,因此您在设计android应用程序时应了解com.google.android.c2dm.intent.REGISTRATION意图可能会多次调用。您的Android应用程序需要能够做出相应的响应。 我使用以下代码注册设备: GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context); String regID = gcm.register(senderID); GoogleCloudMessaging类封装了注册过程。那我该如何处理com.google.android.c2dm.intent.REGISTRATION,因为该处理是由GoogleCloudMessaging类在内部完成的?


13
在ListView中隐藏页脚视图?
我有一个ListView。每当用户一直滚动到底部时,就会从Internet上以10到30组的数据集获取其背后的数据。为了表明它正在加载更多项目,我曾经addFooterView()添加一个简单的视图,该视图显示“正在加载...”消息和一个微调框。现在,当我没有数据(没有更多要提取的数据)时,我想隐藏该消息。我试着做: loadingView.setVisibility(View.GONE); 不幸的是,尽管它确实隐藏了视图,但为它留下了空间。也就是说,我最后有一个很大的空白,以前是“正在加载”消息的地方。我该如何正确隐藏此视图? 我无法使用,removeFooterView()因为可能需要再次显示它,在这种情况下addFooterView(),由于已在上设置了适配器,因此无法再次调用ListView,并且在设置适配器后无法调用addHeaderView()/ addFooterView()。
78 android  listview 

3
Android模拟器:默认选择AVD(Android虚拟设备)运行
我添加了第二个虚拟设备以测试不同的屏幕分辨率(QVGA),但是现在我想再次切换回第一个AVD(HVGA)。如何在Eclipse中将虚拟设备设置为默认使用,甚至专门用于我的项目?在属性中,我只能设置API级别。 我也找不到命令行工具文档中的任何信息来手动设置。
78 android  eclipse  avd 

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.