Questions tagged «android»

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

20
如何设置视图的背景色
我正在尝试设置视图(在这种情况下为按钮)的背景颜色。 我使用以下代码: // set the background to green v.setBackgroundColor(0x0000FF00 ); v.invalidate(); 这会使按钮从屏幕上消失。我在做什么错,在任何视图上更改背景颜色的正确方法是什么? 谢谢。
178 android  view  colors  background  set 


30
亚行找不到我的设备/电话(MacOS X)
在Mac和我拥有的这款非常新的手机上进行Android开发不会出现在adb的设备列表中。许多其他电话和设备对我来说都可以正常工作,所以我知道我的设置很好。 我已经在手机上启用了调试功能(设置->应用程序->开发-> USB调试),但是在运行时却没有显示 adb devices
178 android  adb 

15
嵌套的回收站视图高度不包含其内容
我有一个管理书籍收藏(例如播放列表)的应用程序。 我想在垂直的RecyclerView中显示收藏列表,在每行中显示水平的RecyclerView中的图书列表。 当我将内部水平RecyclerView的layout_height设置为300dp时,它可以正确显示,但是当我将其设置为wrap_content时,它不显示任何内容。 我需要使用wrap_content,因为我希望能够以编程方式更改布局管理器以在垂直和水平显示之间切换。 你知道我在做什么错吗? 我的片段布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white"> <com.twibit.ui.view.CustomSwipeToRefreshLayout android:id="@+id/swipe_container" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/shelf_collection_listview" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="10dp"/> </LinearLayout> </com.twibit.ui.view.CustomSwipeToRefreshLayout> </LinearLayout> 集合元素布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FFF"> <!-- Simple Header --> </RelativeLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="@string/empty_collection" …

24
getActionBar()返回null
我有一个奇怪的问题。我正在使用targetsdk 13开发一个应用程序。 在我的主要活动的onCreate方法中,我调用getActionBar()来设置我的操作栏。在Android 3.2模拟器上运行时,此方法工作正常,但在使用Android 3.0和3.1时,该getActionBar()方法返回null。 我觉得这很奇怪,而且我看不出任何理由这样做。这是模拟器的错误,还是我需要做一些事情,以确保我的应用程序具有操作栏? 解决方案: 我想我已经找到了解决该问题的方法。我没有使用setContentView设置活动的布局。相反,我fragmentTransaction.add(android.R.id.content, mFragment, mTag)用来向活动添加片段。在3.2中可以正常使用,但是在早期的蜂窝版本中,如果您未在onCreate()方法中使用setContentView,则显然不会设置操作栏。因此,我通过在setContentView()方法中使用方法来修复它,onCreate()并为其提供了包含一个空FrameLayout的布局。我仍然可以fragmentTransaction.add(android.R.id.content, mFragment, mTag)像以前一样使用该方法。 这不是最漂亮的解决方法,但是可以解决。

2
在build.gradle文件中写注释的语法是什么?
向下看这个build.gradle文件 apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "package.myapp" minSdkVersion 19 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.nineoldandroids:library:2.4.0' } 如果我想什么写评论我为什么选择这个库为这个项目, 在build.gradle文件中写注释的语法是什么?

9
如何在Android中制作文件的副本?
在我的应用程序中,我想用不同的名称(从用户那里得到)保存某个文件的副本。 我真的需要打开文件的内容并将其写入另一个文件吗? 最好的方法是什么?
177 java  android 

11
android:触摸移动视图(ACTION_MOVE)
我想做一个简单的控件:一个带有视图的容器。如果我触摸容器并移动手指,则希望移动视图以跟随手指。 我应该使用哪种容器(布局)?这该怎么做? 我不需要使用表面,而是使用简单的布局。
177 android  touch 

1
如何使用代码而不是xml设置ImageView的边距
我想给ImageView边缘添加未知数量的视图。在XML中,我可以这样使用layout_margin: <ImageView android:layout_margin="5dip" android:src="@drawable/image" /> 有ImageView.setPadding(),但没有ImageView.setMargin()。我认为这是基于的思路ImageView.setLayoutParams(LayoutParams),但不确定该添加什么。 有人知道吗?


1
从资产读取文件
public class Utils { public static List<Message> getMessages() { //File file = new File("file:///android_asset/helloworld.txt"); AssetManager assetManager = getAssets(); InputStream ims = assetManager.open("helloworld.txt"); } } 我正在使用此代码尝试从资产读取文件。我尝试了两种方法来做到这一点。首先,使用时File我收到FileNotFoundException,使用AssetManager getAssets()方法不被识别。这里有什么解决办法吗?
177 android 

5
多渐变形状
我想创建一个类似于下图的形状: 请注意,从颜色1到颜色2的上半部渐变,但是从颜​​色3到颜色4的下半部渐变。两半,并以2种不同的渐变制成1个形状。 有任何想法吗?
177 android  gradient  shapes 

4
为什么不总是使用android:configChanges =“ keyboardHidden | orientation”?
我想知道为什么不在 android:configChanges="keyboardHidden|orientation"每个(几乎每个;)活动中使用它? 产品: 无需担心您的活动被轮换 更快 不太好: 如果它们取决于屏幕大小,则需要更改布局(例如,两列左右的布局) 坏: 没有灵活的方法来在不同的方向上具有不同的布局 使用片段时不太好 但是,如果我们不使用不同的布局,那为什么不呢?

9
Android:存储用户名和密码?
如果我想存储要在Android应用程序中使用的用户名和密码,最好的方法是什么?是通过首选项屏幕(但是,如果用户错过了呢?),还是弹出一个对话框并询问用户凭据?如果是这样,我必须维护应用程序的状态。我该怎么做?

18
安装失败并显示消息无效文件
安装失败并显示消息无效文件:K:\ project \ app \ build \ intermediates \ split-apk \ with_ImageProcessor \ debug \ slices \ slice_0.apk。可以通过卸载apk的现有版本(如果存在)然后重新安装来解决此问题。 警告:卸载将删除应用程序数据! 您要卸载现有的应用程序吗? 我正在android studio 2.3 beta 3中运行我的项目。

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.