Questions tagged «android»

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

4
在AsyncTask中获取上下文
我正在尝试在名为Opciones的类的AsyncTask中获取上下文(该类是调用该任务的唯一类),但是我不知道该怎么做,我看到了一些类似这样的代码: protected void onPostExecute(Long result) { Toast.makeText(Opciones.this,"Subiendo la foto. ¡Tras ser moderada empezara a ser votada!: ", Toast.LENGTH_LONG).show(); } 但这对我不起作用,它说: "No enclosing instance of the type Opciones in scope"

6
在Android中删除油漆标志
我的代码如下所示: TextView task_text = (TextView) view.findViewById(R.id.task_text); task_text.setPaintFlags( task_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); 这将导致删除线效果出现在文本上。但是,我想知道如何在设置标志后删除该标志,以及如何检测已设置标志。 我知道这是个按位操作,但是我尝试了〜和-运算符,但都没有用。

9
如何同时为Button应用形状和选择器?
我已经为按钮应用了形状,例如: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:startColor="#DD000000" android:endColor="#DD2d2d2d" android:angle="90"></gradient> <corners android:radius="15dip"></corners> </shape> 现在我想使用一个选择器,例如: <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/active" android:state_pressed="true" /> <item android:drawable="@drawable/passive"/> 对于此按钮也是如此。可能吗 ...???

14
使用gradle构建库项目时,BuildConfig.DEBUG始终为false
当我在调试模式下运行应用程序时,BuildConfig.DEBUG无法正常工作(=逻辑上设置为false)。我使用Gradle构建。我有一个图书馆项目,我要检查一下。BuildConfig.java在构建调试文件夹中如下所示: /** Automatically generated the file. DO NOT MODIFY */ package common.myProject; public final class BuildConfig { public static final boolean DEBUG = Boolean.parseBoolean("true"); } 并在release文件夹中: public static final boolean DEBUG = false; 在库项目和应用程序项目中。 我试图通过检查设置项目类的变量来解决此问题。此类从库继承,并在启动时开始。 <application android:name=".MyPrj" ... 这导致了另一个问题:是我在DataBaseProvider中使用了DEBUG变量,该变量在应用程序类之前运行,并且由于此错误而无法正常运行。

2
从Android中的Google Map清除标记
我已经添加了有关片段活动的地图,并使用addMarker函数添加了几个标记,但是我能够删除所有标记,并收到有关标记列表的通知, 现在我想删除所有标记并添加新标记。 一种将所有标记保留在列表中并一一删除的方法(marker.remove()) 有没有更好的办法清除所有标记。

5
在Android中解析HTML
我正在尝试从网页中解析android中的HTML,由于该网页的格式不正确,我得到了SAXException。 有没有一种方法可以在Android中解析HTML?
83 android  html  parsing 


6
如何在TextView文本中添加图像?
我在Google上四处搜索,发现该网站与我的网站类似,在其中如何在图片中包含图片TextView,例如“ hello my name is [image]”,答案是这样的: ImageSpan is = new ImageSpan(context, resId); text.setSpan(is, index, index + strLength, 0); 我想知道这段代码, 我应该在上下文中键入或做什么? 我应该对text.setSpan()导入或引用做些什么,还是将其保留为文本? 如果有人可以帮我解决这个问题,将不胜感激。
83 java  android  xml  image  textview 

12
如何设置导航抽屉从右向左打开
首先,我知道这个问题以前曾出现在这里,但经过很多尝试,我仍然没有成功。我在Android Developers网站上处理示例 。 我试图将菜单设置为从右向左打开,而不是在示例中如何实现(从左向右)。另外,我想将打开的菜单按钮移到操作栏的右侧。我在这里也给出了一些答案,例如这个答案。 我尝试更改视图和布局的重力,但出现错误: 绝对重力未找到抽屉视图 您能帮我找出代码中的问题是什么,我应该更改什么才能将菜单设置为从右侧打开,并将操作栏按钮移至右侧? xml代码在这里: <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_gravity="right" android:layout_width="match_parent" android:layout_height="match_parent" > <FrameLayout android:id="@+id/content_frame" android:layoutDirection="rtl" android:layout_width="match_parent" android:layout_height="match_parent" /> <ListView android:id="@+id/left_drawer" android:layout_width="200dp" android:layout_height="match_parent" android:layout_gravity="right" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="10dp" android:background="#111"/> </android.support.v4.widget.DrawerLayout>

7
如何在Android Studio中使用ADB查看SQLite数据库
我需要查看我的SQLite数据库,但我不知道该怎么做。我已经转到http://www.sqlite.org/download.html并下载了适用于我的OS的命令行外壳程序,但是当我运行该程序并键入内容时,adb ...出现错误。 注意:我使用的是Android Studio,所以我假设不需要安装其他任何东西,因为我记得Android Studio说它具有所需的所有SDK工具。
83 android  adb 

6
从文件路径创建位图/绘图
我正在尝试从现有文件路径创建位图或可绘制对象。 String path = intent.getStringExtra("FilePath"); BitmapFactory.Options option = new BitmapFactory.Options(); option.inPreferredConfig = Bitmap.Config.ARGB_8888; mImg.setImageBitmap(BitmapFactory.decodeFile(path)); // mImg.setImageBitmap(BitmapFactory.decodeFile(path, option)); // mImg.setImageDrawable(Drawable.createFromPath(path)); mImg.setVisibility(View.VISIBLE); mText.setText(path); 但是setImageBitmap(),setImageDrawable()不会显示路径中的图像。我已经打印了路径,mText它看起来像:/storage/sdcard0/DCIM/100LGDSC/CAM00001.jpg 我究竟做错了什么?有人可以帮助我吗?

8
getLastKnownLocation返回null
我已经阅读了有关此问题的一些问题,但并没有找到我需要的答案。 因此,情况是我已经设置了地图,并且想要获取当前的GPS位置。我检查过我的变量不是NULL,但是我的结果是: getLastKnownLocation(provider, false); 虽然给我null,所以这是我需要帮助的地方。我已经添加了对COARSE + FINE位置的权限。但是我通常会禁用手机的各种网络数据,因为我对手机账单中不可预测的数据流费用感到不满意。因此,此测试仅启用并连接了WiFi。 为了使之成为可能,我还需要启用更多功能吗?我认为WiFi应该足够了吗?

4
Android:将数据(扩展名)传递给片段
我是Android编程的新手,将Parcelable的ArrayList传递给片段时遇到了问题。这是启动的活动(效果很好!),其中feedlist是可打包音乐的ArrayList。 Intent in = new Intent(context, ListMusicsActivity.class); in.putExtra("arrayMusic", feedList); activity.startActivity(in); 片段Activity onCreate()方法: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activitymusiclist); if(savedInstanceState != null) { ListMusicFragment frag = new ListMusicFragment(); frag.setArguments(getIntent().getExtras()); } } 片段代码: public class ListMusicFragment extends SherlockFragment{ private ArrayList<Music> listMusics = new ArrayList<Music>(); private ListView listMusic; @Override public View …

4
如何在Android中写入SD卡上的文件夹?
我正在使用以下代码从服务器下载文件,然后将其写入SD卡的根目录,一切正常: package com.downloader; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import android.os.Environment; import android.util.Log; public class Downloader { public void DownloadFile(String fileURL, String fileName) { try { File root = Environment.getExternalStorageDirectory(); URL u = new URL(fileURL); HttpURLConnection c = (HttpURLConnection) u.openConnection(); c.setRequestMethod("GET"); c.setDoOutput(true); c.connect(); FileOutputStream f = …

30
Android Studio-无法通知项目评估监听器错误
以下是Android Studio中的build.gradle代码 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.sg.blahblah" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } lintOptions { checkReleaseBuilds true abortOnError false xmlReport true htmlReport true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' lintOptions { disable 'MissingTranslation' } } …

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.