Questions tagged «android»

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


3
Android XML Layout的'include'标签确实有效吗?
在我的Android布局文件中使用<include>时,我无法覆盖属性。当我搜索错误时,发现拒绝的问题2863: “ include标记已损坏(覆盖的布局参数永远无效)” 由于Romain指出这在测试套件及其示例中有效,因此我一定做错了。 我的项目是这样组织的: res/layout buttons.xml res/layout-land receipt.xml res/layout-port receipt.xml button.xml包含以下内容: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <Button .../> <Button .../> </LinearLayout> 人像和风景的receive.xml文件看起来像: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> ... <!-- Overridden attributes never work. Nor do attributes like the red background, which is specified here. --> <include android:id="@+id/buttons_override" android:background="#ff0000" android:layout_width="fill_parent" …

7
警告:请勿将Android上下文类放在静态字段中;这是内存泄漏(并且还会中断即时运行)
Android Studio: 不要将Android上下文类放在静态字段中;这是内存泄漏(并且还会中断即时运行) 所以有两个问题: #1您如何startService从没有静态变量的静态方法中调用a ? #2您如何通过静态方法(相同)发送localBroadcast? 例子: public static void log(int iLogLevel, String sRequest, String sData) { if(iLogLevel > 0) { Intent intent = new Intent(mContext, LogService.class); intent.putExtra("UPDATE_MAIN_ACTIVITY_VIEW", "UPDATE_MAIN_ACTIVITY_VIEW"); mContext.startService(intent); } } 要么 Intent intent = new Intent(MAIN_ACTIVITY_RECEIVER_INTENT); intent.putExtra(MAIN_ACTIVITY_REQUEST_FOR_UPDATE, sRequest)); intent.putExtra(MAIN_ACTIVITY_DATA_FOR_VIEW, sData); intent.putExtra(MAIN_ACTIVITY_LOG_LEVEL, iLogLevel); LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); 不使用此方法的正确方法是什么mContext? 注意:我认为我的主要问题可能是如何将上下文传递给调用方法所在的类。

8
使用Volley发送带有JSON数据的POST请求
我想发送一个新JsonObjectRequest请求: 我想接收JSON数据(来自服务器的响应):确定 我想将带有此请求的JSON格式的数据发送到服务器 JsonObjectRequest request = new JsonObjectRequest( Request.Method.POST, "myurl.com", null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { //... } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { //... } }) { @Override protected Map<String,String> getParams() { // something to do here ?? return params; } …

1
使用Rxjava Schedulers.newThread()与Schedulers.io()进行改造
什么是使用的好处Schedulers.newThread()VSSchedulers.io()在Retrofit网络请求。我已经看到了许多使用的示例io(),但是我想理解为什么。 情况示例: observable.onErrorResumeNext(refreshTokenAndRetry(observable)) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread())... 与 observable.onErrorResumeNext(refreshTokenAndRetry(observable)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread())... 我见过的原因之一是- newThread()为每个工作单元创建一个新线程。io()将使用线程池 但是,这种说法对应用程序有什么影响?还有其他哪些方面?


28
在edittext上时如何禁用键盘弹出窗口?
在我的应用程序中,所有屏幕的第一个视图都是EditText,因此每次我转到屏幕时,屏幕上的键盘都会弹出。当手动单击EditText时,如何禁用此弹出窗口并启用它? eT = (EditText) findViewById(R.id.searchAutoCompleteTextView_feed); eT.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if(hasFocus){ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(eT.getWindowToken(), 0); } } }); xml代码: <ImageView android:id="@+id/feedPageLogo" android:layout_width="45dp" android:layout_height="45dp" android:src="@drawable/wic_logo_small" /> <Button android:id="@+id/goButton_feed" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="@string/go" /> <EditText android:id="@+id/searchAutoCompleteTextView_feed" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toLeftOf="@id/goButton_feed" android:layout_toRightOf="@id/feedPageLogo" android:hint="@string/search" /> <TextView android:id="@+id/feedLabel" …


14
无法解决:com.android.support:appcompat-v7:26.0.0
我在Android Studio中遇到此问题。 Error:(22, 13) Failed to resolve: com.android.support:appcompat-v7:26.0.0 <a href="install.m2.repo">Install Repository and sync project</a><br><a href="openFile:C:/Users/username/AndroidStudioProjects/ElectroSave/app/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a> 这是我的Gradle代码: apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.example.noelly.myapplication" minSdkVersion 19 targetSdkVersion 25 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled …

12
进行动态但正方形布局的简单方法
我正在使用aGridView来显示一堆基本上是的视图LinearLayouts。我希望LinearLayouts它们都为正方形,但我也希望它们为动态大小-也就是说,有两列,我希望LinearLayouts根据屏幕的大小进行拉伸,但保持正方形。有没有办法通过xml布局来做到这一点,还是必须以编程方式设置高度和宽度?
84 android 

8
动作栏的“主页”按钮的onClick侦听器
如何onClickListener为操作栏的“主页”按钮实现自定义? 我已经做了一个操作getSupportActionBar().setDisplayHomeAsUpEnabled(true);,现在我想将用户重定向到某个活动,以防单击“主页”按钮。 我尝试了: @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: item.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Intent i = new Intent(); i.setClass(BestemmingActivity.this, StartActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); return true; } }); default: return super.onOptionsItemSelected(item); } } 但它永远不会进入onMenuItemClick。 基本上,它就像在此链接中一样完成,但仍未输入到侦听器中。

2
Android:以编程方式从Java代码填充Spinner
您如何以编程方式从Java代码填充微调框? 我在布局中有一个微调器,如下所示: <Spinner android:id="@+id/consultation_deseases" android:layout_width="@dimen/bigSpinnerWidth" android:layout_height="@dimen/bigSpinnerHeight" android:prompt="@string/disease_prompt" /> 使用Java代码,我需要创建适配器并添加项目。

10
api <21的可绘制着色
是否可以使api &lt;21的可绘制着色工作? &lt;bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/ic_calendar" android:tint="@color/primary" /&gt; 效果很好,但仅适用于具有API21的设备。较低api设备或AppCompat支持的任何解决方法?找不到任何东西。
84 android 

7
如何用左上角的圆角和左下角的圆角制作形状?
我想用左上角的圆角和左下角的圆角制作形状: &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;solid android:color="#555555"/&gt; &lt;stroke android:width="3dp" android:color="#555555" /&gt; &lt;padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" /&gt; &lt;corners android:bottomRightRadius="0dp" android:bottomLeftRadius="2dp" android:topLeftRadius="2dp" android:topRightRadius="0dp"/&gt; &lt;/shape&gt; 但是上面的形状没有给我我想要的东西。它给了我一个没有任何圆角的矩形。

9
从软键盘截取后退按钮
我有几个输入字段的活动。活动开始后,将显示软键盘。当按下后退按钮软键盘关闭并关闭活动时,我需要再按下一次后退按钮。 因此,问题是:是否可以拦截后退按钮以关闭软键盘并在不创建自定义功能的情况下按一下后退按钮来完成活动InputMethodService? PS我知道在其他情况下如何拦截后退按钮:onKeyDown()或者,onBackPressed()但在这种情况下不起作用:只有第二次按下后退按钮才能被拦截。
84 android 

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.