我有一个包含片段的活动,片段包含自定义视图.customview包含一个edittext,并在其下方是一个高度为match_parent的recyclerview.当用户专注于edittext时,会出现一个软输入键盘.不幸的是,这个键盘隐藏了它下面的一半Recyclerview.我希望recyclerview调整大小到屏幕的剩余可见高度(在edittext下),这样列表中的项目不会被键盘隐藏.
我已尝试为清单中的活动设置adjustresize,但它没有效果:
android:windowSoftInputMode="adjustResize"
Run Code Online (Sandbox Code Playgroud)
我已经尝试将我的应用主题设置为基本主题(如果我的自定义主题中的某些内容导致问题) - 没有效果:
android:theme="@style/Theme.AppCompat.NoActionBar"
Run Code Online (Sandbox Code Playgroud)
我已经检查过以确保层次结构中的任何地方都没有框架布局到必须调整大小的视图(我读了一个SO线程,这可能是个问题) - 没有.
我检查了活动,片段,自定义视图和连接的每个适配器,以确保我没有在任何地方调用getWindow(我不是).
自定义视图在运行时从视图存根中膨胀.这有联系吗?
编辑:
父母的内容:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
...
<ViewStub
android:id="@+id/viewstub_outername"
android:layout="@layout/viewstub_thatIneed"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
viewstub的内容:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewstub_root"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@android:color/white"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:visibility="invisible"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:visibility="invisible"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这样显示键盘:
public static void showSoftKeyboard(Activity activity) {
View view = activity.getCurrentFocus();
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
Run Code Online (Sandbox Code Playgroud) 有没有一种不需要 Google Play 服务就可以实现 Google 登录的方法?我知道官方文档说你需要 GPS:
• https://developers.google.com/identity/sign-in/android/start-integrating
但是我也在这里发现了相互矛盾的信息:
•没有 Google Play 服务的 Google Plus 登录
也就是说,使用 Google+ Api 您可以在用户没有 GPS 的情况下实现登录。哪个是真的?从技术上讲,您可以在没有 GPS 的情况下实现登录吗?如果可以的话,对于因任何原因无法下载 GPS 的用户来说,作为后备使用会很好。
android google-play-services google-plus-signin android-googleapiclient google-signin
我想设置一个项目来构建两个可以安装在同一设备上的不同apks - 其中一个是生产apk,第二个是调试apk.为此,我在build.gradle中定义了:
buildTypes {
release {
}
debug {
applicationIdSuffix = ".debug"
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试同步gradle时,我得到错误:
Error:org.gradle.api.GradleException: No matching client found for package name 'mypkg.debug'
Run Code Online (Sandbox Code Playgroud)
除了build.gradle的buildTypes部分之外,我还应该做些什么来使其正常工作?
android build.gradle android-gradle-plugin android-build-type android-gradle-2.0
我正在为使用第三方库的应用程序配置Proguard.它是"最佳实践"(为了避免将来难以发现的错误)包含该行:
-keep class 3rd_party_lib_name.** {*;}
Run Code Online (Sandbox Code Playgroud)
对于没有其开发人员的特定Proguard指令的每个第三方开源库?
另外,一个相关的问题是:我应该使用哪些案例的一般准则
-keep class
Run Code Online (Sandbox Code Playgroud)
在哪些情况下我应该使用
-keep public class
Run Code Online (Sandbox Code Playgroud)
非常感谢
我有一个在清单中定义的活动:
android:launchMode="singleInstance"
Run Code Online (Sandbox Code Playgroud)
现在我想从一个不知道它存在的不同活动(没有引用现有实例)并同时传入一个变量转移到该活动.我曾经这样做(在我将其定义为singleInstance之前):
Intent intent = new Intent(this, receivingactivity.class);
intent.putExtra("somekey", somevalue);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
但现在这已不再适用了.我在onresume中接收了以下行的接收活动:
String somevalue = getIntent().getStringExtra("somekey");
Run Code Online (Sandbox Code Playgroud)
它返回null.如何将值传递给现有的接收活动(该活动始终处于活动状态且永远不会达到ondestroy但最大值会延迟到暂停)?
我有一个包含谷歌地图的片段:
<com.google.android.gms.maps.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraZoom="13"
map:mapType="normal"
map:uiZoomControls="false"
map:uiRotateGestures="true"
map:uiScrollGestures="true"
map:uiZoomGestures="true"
map:uiTiltGestures="false" />
Run Code Online (Sandbox Code Playgroud)
地图占据整个屏幕并启用了mylocation:
map.setMyLocationEnabled(true);
Run Code Online (Sandbox Code Playgroud)
以下代码应将 mylocation按钮与屏幕的左上角对齐:
// Get the mylocation button view
View locationButton = ((View) mapview.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
Run Code Online (Sandbox Code Playgroud)
但是 - 这只会将按钮与屏幕的顶部中心对齐.但是,如果我添加这个:
if (Build.VERSION.SDK_INT >= 17) {
rlp.addRule(RelativeLayout.ALIGN_PARENT_START);
}
Run Code Online (Sandbox Code Playgroud)
然后它正确地对齐左边.问题是在api 17之前不能以编程方式使用ALIGN_PARENT_START,我需要从较低的api级别支持.为什么align_parent_left不能独立工作以将按钮对齐到左边?
我有一个支持工厂定义如下:
<android.support.design.widget.FloatingActionButton
android:id="@+id/somefab"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
app:elevation="6dp"
app:rippleColor="@android:color/white"
/>
Run Code Online (Sandbox Code Playgroud)
如果我像这样以编程方式设置backgroundtintlist,那么它可以工作:
somefab.setBackgroundTintList(ColorStateList.valueOf(Color.GRAY));
Run Code Online (Sandbox Code Playgroud)
但是,这是一个支持工厂,应该在较低的apis上可见,所以我想使用支持方法:
somefab.setSupportBackgroundTintList(ColorStateList.valueOf(Color.GRAY));
Run Code Online (Sandbox Code Playgroud)
在这里我已经得到一个空指针异常.
java.lang.RuntimeException: Unable to start activity ComponentInfo{myprojectpath}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4077)
at android.app.ActivityThread.-wrap15(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable()' on a null object reference
at android.graphics.drawable.LayerDrawable$ChildDrawable.<init>(LayerDrawable.java:1723)
at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:1792)
at android.graphics.drawable.RippleDrawable$RippleState.<init>(RippleDrawable.java:998)
at android.graphics.drawable.RippleDrawable.createConstantState(RippleDrawable.java:989) …Run Code Online (Sandbox Code Playgroud) android android-support-library floating-action-button android-support-design
我正在使用 okhttp 向我的服务器发送请求。问题是 okhttp 发送的请求缺少内容长度标头 - 我可以手动设置标头:
Request.builder
....
.addHeader("content-length","some-value")
Run Code Online (Sandbox Code Playgroud)
但我无法获得适当的价值放在那里。如果我尝试像这样测量我的请求正文:
int request_length = body.length();
builder.addHeader("content-length", String.valueOf(request_length));
Run Code Online (Sandbox Code Playgroud)
然后 okhttp 根本不添加标题。
是否有将内容长度标头添加到请求的正确方法(最好是“默认”添加标头的方法)?
我有一个谷歌地图,当用户围绕蓝点(myLocation)移动时 - 标准行为。这很有效,直到用户移动到当前缩放级别的边界之外 - 并且蓝点从地图的边缘之一消失。我不想在用户每次移动并获得位置更新时重新聚焦地图 - myLocation 点没有必要始终位于屏幕的中心 - 但 myLocation 有必要始终可见,因此如果用户离开地图的一侧,我想重新调整地图的焦点,以便他再次可见。
如何判断 myLocation 已移出屏幕的可见区域?
我的一个项目有多个第三方库,其中一个库正在请求我在Manifest中没有定义的权限.如何找出哪些库请求许可?
如果我执行命令:
adb shell dumpsys package [mypackagename]
Run Code Online (Sandbox Code Playgroud)
然后我将权限视为"已请求",但正如我所提到的,它在我的项目中不存在.有很多第三方库.
performance android adb android-manifest android-permissions
android ×10
java ×4
adb ×1
build.gradle ×1
google-maps ×1
http ×1
instance ×1
maps ×1
okhttp ×1
performance ×1
proguard ×1