Questions tagged «android»

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

5
确定ViewPager何时更改页面
我在ViewPager中有三个页面(片段),但是我只想显示其中两个页面的菜单项。 先前的SO答案中给出的代码似乎无效: @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); if (isVisibleToUser == true) { } else if (isVisibleToUser == false) { } } Eclipse表示不需要@Override,也无法设置super。它从未被系统调用,即使这是我如何确定当前显示的页面呢?我可以在这里帮忙吗?

14
如何在RecyclerView上正确突出显示所选项目?
我正在尝试使用a RecyclerView作为水平ListView。我试图弄清楚如何突出显示所选项目。当我单击其中一项时,将其选中并正确突出显示,但是当我单击另一项时,第二项将与较旧的一起突出显示。 这是我的onClick函数: @Override public void onClick(View view) { if(selectedListItem!=null){ Log.d(TAG, "selectedListItem " + getPosition() + " " + item); selectedListItem.setBackgroundColor(Color.RED); } Log.d(TAG, "onClick " + getPosition() + " " + item); viewHolderListener.onIndexChanged(getPosition()); selectedPosition = getPosition(); view.setBackgroundColor(Color.CYAN); selectedListItem = view; } 这是onBindViewHolder: @Override public void onBindViewHolder(ViewHolder viewHolder, int position) { …

6
片段中的片段
我想知道这是否真的是Android API中的错误: 我有这样的设置: ┌----┬---------┐ | | | | 1 | 2 | | |┌-------┐| | || || | || 3 || └----┴┴-------┴┘ 是在右窗格中加载片段2(搜索屏幕)的菜单。 是一个搜索屏幕,其中包含片段#3,这是结果列表。 结果列表已在多个地方使用(本身就是一个功能完善的高级片段)。 此功能在手机上(在1&2和3是ActivityFragments的情况下)效果很好。 但是,当我使用此代码时: FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); Fragment frag = new FragmentNumber2(); if(toLoad != null) frag.setArguments(toLoad); transaction.replace(R.id.rightPane, frag); transaction.commit(); 其中R.id.leftPane和R.id.rightPane是<fragment>水平线性布局中的。 据我了解,以上代码删除了驻留的片段,然后将其替换为新的片段。太棒了……显然,这不会发生,因为当此代码第二次运行时,您会收到以下异常: 07-27 15:22:55.940: ERROR/AndroidRuntime(8105): Caused by: …

3
应用程序可以使用的最大RAM数量是多少?
我对这个与Android操作系统的内存管理有关的问题非常好奇,因此我希望就该主题提供一个非常详细的答案。 我想知道的是: Android应用程序(不是系统应用程序)可以使用的最大内存量(兆字节 / 占总RAM的百分比)是多少? Android版本之间有什么区别吗? 关于设备制造商有什么区别吗? 最重要的是: 什么被视为/ 这是什么取决于当它涉及到系统中确定多少内存的应用程序可以在运行时使用(假设每个应用程序的内存最大是不是一个静态的数字)? 到目前为止(截至2013年)我所听到的: 早期的Android设备的每个应用上限为16MB 后来这个上限增加到24MB或32MB 是什么让我非常好奇: 这两个限制都非常低。 我刚刚下载了Android任务管理器,以检查设备的RAM。我注意到的是,有些应用程序使用大约40-50 MB的RAM,这比上面提到的最大RAM使用量(例如32 MB)要明显得多。那么Android如何确定一个应用可以使用多少RAM?应用程序怎么可能超过该限制? 此外,我注意到当使用大约30-40 MB时,我的一些应用程序崩溃了(被系统杀死了?),并带有OutOfMemoryException。另一方面,一段时间后(可能是由于内存泄漏),我的手机上使用的应用程序使用的内存为100 MB以上,并且不会崩溃或消失。因此,在确定可以保留多少RAM时,显然还取决于应用程序本身。这怎么可能?(我使用具有768 MB RAM的HTC One S进行了测试) 免责声明:我不以任何方式与Android Task Manager应用关联。

9
密钥必须是特定于应用程序的资源ID
为什么会出现此异常? 05-18 20:29:38.044: ERROR/AndroidRuntime(5453): java.lang.IllegalArgumentException: The key must be an application-specific resource id. 05-18 20:29:38.044: ERROR/AndroidRuntime(5453): at android.view.View.setTag(View.java:7704) 05-18 20:29:38.044: ERROR/AndroidRuntime(5453): at com.mypkg.viewP.inflateRow(viewP.java:518) 有问题的行是: ((Button) row.findViewById(R.id.btnPickContact)).setTag(TAG_ONLINE_ID,objContact.onlineid); 我将其定义为: private static final int TAG_ONLINE_ID = 1;


15
USB调试选项显示为灰色
我有运行Android 2.3.6的LG-E405手机。 我用USB电缆连接了手机,并将模式选择为Charge Only。 现在,当我尝试打开时USB Debugging,我发现该选项为灰色。 因此,在这种情况下如何启用USB调试。
145 android  usb  adb 


13
活动中的全屏背景图片
我看到许多应用程序使用全屏图像作为背景。这是一个例子: 我想在项目中使用它,到目前为止,我发现最好的方法是使用大尺寸的图像,将其放在中ImageView并用于android: adjustViewBounds="true"调整边距 问题是,如果屏幕的分辨率很高,则图像不足。 我想到的另一种选择是在FrameLayout,match_parentin width和height作为背景中使用图像...这会拉伸图像,但我认为结果不是很好。 你会怎么做?

17
找不到资源-Theme.AppCompat.Light.DarkActionBar
我使用了ActionBar Style Generator,现在尝试在我的应用程序中使用,但是得到: 错误:检索项目的父项时出错:找不到与给定名称'@ style / Theme.AppCompat.Light.DarkActionBar'匹配的资源。 我正在libs文件夹中使用android-support-v7-appcompat.jar lib 我的目标是使我的应用程序兼容2.3或更高版本

4
处理EditText焦点的事件
有人可以建议我发生与焦点有关的任何事件EditText吗?我的应用程序包含一个EditText,其中接受一个URL。 现在我的问题是,在用户将在字段中输入URL并继续移动之后,没有任何click事件,即,当焦点将从移到时EditText,它将检测到输入的网址并转到服务器。 如果我使用Json解析得到答复,那么它将更加方便。


7
使用AppCompat ActionBarActivity更改状态栏颜色
在我的一项活动中,我使用更改了工具栏的颜色Palette。但在使用5.0的设备ActionBarActivity的status bar颜色的颜色我colorPrimaryDark我的活动主题,所以我有2种非常不同的颜色和它看起来并不好。 我意识到在5.0中您可以使用,Window.setStatusBarColor()但ActionBarActivity没有此功能。 所以我的问题是在5.0中如何更改状态栏的颜色ActionBarActivity?

11
RecyclerView展开/折叠项目
我想展开/折叠我的recyclerView的项目以显示更多信息。我想实现SlideExpandableListView的相同效果。 基本上在我的viewHolder中,我有一个不可见的视图,我想做一个平滑的展开/折叠动画,而不是将可见性设置为仅VISIBLE / GONE。我只需要一次扩展一个项目,可以稍微抬高以显示该项目已被选中很酷。 这与新的Android最近通话记录列表的效果相同。仅当选择一个项目时,选项“ CALL BACK”和“ DETAILS”才可见。

4
Android:如何以编程方式设置布局的大小
作为Android应用程序的一部分,我正在构建按钮集。这些按钮是一组LinearLayouts的一部分。使用权重,我可以根据包含父级LinearLayout的大小自动调整其大小。这个想法是基于屏幕的像素数和密度,将包含布局的大小设置为多个像素。并根据更改更改按钮的大小。 然后的问题是:如何调整布局的大小。 我已经尝试了几种建议的技术,但没有一种接近工作。这是构建按钮集的XML的子集: <LinearLayout android:layout_height="104pt" android:id="@+id/numberPadLayout" android:orientation="horizontal" android:layout_width="104pt" android:background="#a0a0a0" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" > <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_width="wrap_content"> <Button android:text="1" android:id="@+id/button1" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button> <Button android:text="4" android:id="@+id/button4" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button> <Button android:text="7" android:id="@+id/button7" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button> <Button android:text="-" android:id="@+id/buttonDash" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button> </LinearLayout> <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@+id/linearLayout2" android:orientation="vertical" android:layout_width="wrap_content"> <Button …

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.