Questions tagged «android»

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

9
带有乱码的UTF-8字符的Android WebView。
我在Android应用中使用了一些Webview,但是无法使它们以utf-8编码显示。 如果使用这个,我不会看到我的斯堪的纳维亚字符: mWebView.loadUrl("file:///android_asset/om.html") 如果尝试这个,我什么都不会显示 mWebView.loadDataWithBaseURL("file:///android_asset/om.html", null, "text/html", "utf-8",null); 问候
76 android  webview  utf 

10
如何控制Android中默认警报对话框的宽度和高度?
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Title"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show(); } }); AlertDialog alert = builder.create(); 我正在使用上面的代码来显示警报对话框。默认情况下,它以宽度填充屏幕,以wrapped_content填充高度。 如何控制默认警报对话框的宽度和高度? 我试过了: alert.getWindow().setLayout(100,100); // It didn't work. 如何在警报窗口上获取布局参数并手动设置宽度和高度?


9
带有View.GONE的Android View仍会收到onTouch和onClick
这使我感到困惑: 据我所读,一个带有setVisibility(View.GONE);的视图;不应再收到任何触摸或点击事件。我的布局有两个部分,这两个部分将是可见的或消失的,因此一次只能显示和使用其中的一个,但是View.GONE并不能解决问题。我没有看到GONE视图,正如预期的那样,但是它仍然会对onClick做出反应(并消耗其他视图应该获得的事件)。 你能帮助我吗? 可能感兴趣:当我开始项目时,一个视图已消失,另一个视图可见。这次它将按预期工作(基本上将忽略GONE视图),但是在通过代码设置View.GONE之后,它将停止工作。

4
Android中ImageView的最大宽度和高度
所以我有一个ImageView设置 android:maxHeight="100px" android:maxWidth="250px" android:minHeight="100px" android:minWidth="250px" android:scaleType="centerInside" 该图像视图用于显示从图库或照相机获得的图片。在这两种情况下,都不会调整图像的大小以适合imageview的大小,它只是根据需要扩展其空间。 知道如何使它停留在这些范围内吗? <?xml version="1.0" encoding="utf-8"?> <EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/txtDescription" android:layout_below="@+id/txtSubject" android:inputType="textMultiLine" android:height="80px" android:hint="@string/description"></EditText> <EditText android:layout_height="wrap_content" android:layout_below="@+id/txtDescription" android:layout_width="fill_parent" android:id="@+id/txtMorada" android:hint="@string/address" /> <ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/txtMorada" android:id="@+id/btGPS" android:layout_alignParentLeft="true" android:src="@drawable/ic_menu_compass"></ImageButton> <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/btGPS" android:layout_marginTop="25px" android:id="@+id/imgPoint" android:src="@drawable/google_logo_small" android:maxHeight="100px" android:maxWidth="250px" android:minHeight="100px" android:minWidth="250px" android:scaleType="centerInside"></ImageView> <ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_toRightOf="@+id/imgPoint" android:id="@+id/btGallery" …


10
如何通过Intents打开电子邮件程序(但仅限电子邮件程序)
我想设置应用程序的一部分,允许用户向其他用户发送快速电子邮件。设置起来并不难: Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, message); Intent mailer = Intent.createChooser(intent, null); startActivity(mailer); 但是,问题在于,ACTION_SEND不仅被电子邮件程序接受,例如,在我的手机上,Facebook应用程序,Twitter,reddit很有趣,甚至蓝牙也成为发送此消息的可行选择。对于其中一些消息(特别是Twitter),消息完全太长。 有没有一种方法可以将选择器限制为仅支持长消息的应用程序(例如电子邮件)?还是有一种方法可以检测用户选择的应用并适当地调整消息?
76 android 

6
如何设置gradle和android studio做发布构建?
我想构建android应用并开始对其进行签名。为此,我需要发布apk的发行版。Google文档仅建议使用Eclipse和蚂蚁发布版本的方法:http : //developer.android.com/tools/publishing/app-signing.html#releasecompile 但是我找不到如何强制gradle build发行版本的apk。build.gradle也没有给出任何提示。gradlew tasks建议没有安装发布版本的配置,但存在卸载版本: Install tasks ------------- installDebug - Installs the Debug build installTest - Installs the Test build for the Debug build uninstallAll - Uninstall all applications. uninstallDebug - Uninstalls the Debug build uninstallRelease - Uninstalls the Release build uninstallTest - Uninstalls the Test build for the …

8
如何设置网页视图的初始缩放/宽度
我正在尝试使WebView具有与android浏览器类似的行为。浏览器以试图使其宽度适合屏幕的方式打开所有页面。但是,WebView的默认行为是从100%像素比例开始,因此它开始在左上角放大。 在过去的几个小时中,我试图找到一种方法来使WebView像在浏览器中一样将页面缩放到屏幕上,但是我没有运气。有没有人找到实现这一目标的方法? 我看到的是一个名为setLoadWithOverviewMode的设置,但这似乎根本没有做任何事情。我还尝试了setInitialScale,但在不同的屏幕尺寸和网页尺寸上却没有浏览器缩放那样优雅。 任何人都有线索吗? 谢谢 编辑:Brian的方法似乎在手机处于横向而不是纵向时有效。在纵向中,它很接近,但仍不能适合页面中的整个屏幕。我希望以此为出发点,希望能有一种可靠的方法来使初始缩放比例适合页面在任何方向或屏幕尺寸下的宽度。

8
将对象从活动传递到片段
我有一个Activity使用Fragment。我只是想将一个对象从此传递Activity给Fragment。 我该怎么办?到目前为止,我看过的所有教程都是从资源中检索数据的。 编辑: 让我们更精确一点: 我的活动ListView左侧有一个。当您单击它时,其想法是Fragment在右侧加载一个。 当我输入此内容时Activity,将Category通过给出一个对象Intent。该对象包含其他对象的列表Questions(其中包含字符串的列表)。这些Questions对象显示在ListView上。当我点击从一个项目ListView,我想显示的列表String到Fragment(入ListView)。 为此,我setContentView()从Activity布局中调用。在此布局中,定义了Fragment要调用的正确类。当我调用this时setContentView(),onCreateView()我的会Fragment被调用,但此时getArguments()返回null。 我如何设法在致电之前将其填满onCreateView()?(告诉我,如果我不够清楚) 谢谢
76 android 

7
游标在Android开发中的用途是什么?
我正在浏览互联网上有关数据库连接,检索的一些代码。我Cursor cur1= moveToFirst()在很多代码中都看到了,我想知道游标的用途以及为什么我们要使用moveToFirst()android新手。
76 android  cursor 

11
使用Android检测长按
我目前正在使用 onTouchEvent(MotionEvent event){ } 检测用户何时按下我的glSurfaceView,有一种方法可以检测何时长按。我猜如果我在开发文档中找不到很多东西,那将是围绕方法的某种变通。例如注册ACTION_DOWN并查看ACTION_UP之前需要多长时间。 如何使用opengl-es在android上检测长按?

25
错误:任务':app:processDebugResources'的执行失败。> java.io.IOException:无法在android studio中删除文件夹“”
我试图使用Android Studio开发一个Android应用程序,因此我创建了一个Android应用程序,并希望将其发布。每当我单击“ build project”以获取apk文件时,都会出现此错误: Error:Execution failed for task ':app:processDebugResources'. > java.io.IOException: Could not delete folder C:\Users\ehsan\AndroidStudioProjects\MyApplication3\app\build\generated\source\r\debug\com\example\ehsan Build.gradle: apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.example.ehsan.myapplication" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } …

14
应用程序关闭时,Android服务停止
我正在从主要的Android活动中启动服务,如下所示: final Context context = base.getApplicationContext(); final Intent intent = new Intent(context, MyService.class); startService(intent); 当我通过从最近的应用程序列表中划出活动页面来关闭活动页面时,该服务将停止运行并在一段时间后重新启动。由于我的应用程序要求,我无法将持久性服务与通知一起使用。如何使服务不重新启动或关闭,而仅在应用退出时继续运行?

8
为什么在RecyclerView.Adapter的onBindViewHolder中添加OnClickListener被认为是不好的做法?
我有一个RecyclerView.Adapter类的以下代码,它工作正常: public class MyAdapter extends RecyclerView.Adapter<MyAdapter.Viewholder> { private List<Information> items; private int itemLayout; public MyAdapter(List<Information> items, int itemLayout){ this.items = items; this.itemLayout = itemLayout; } @Override public Viewholder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false); return new Viewholder(v); } @Override public void onBindViewHolder(Viewholder holder, final int …

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.