Tag: android-layout

android – What is the difference between “px”, “dip”, “dp” and “sp”?

The Question : 5943 people think this question is useful What is the difference between Android units of measure? px dip dp sp The Question Comments : this is use full difference between px, dip, dp and sp in android [ developer.android.com/guide/topics/resources/… This nifty converter demonstrates it best, in my opinion. It’s also extremely useful

android – You need to use a Theme.AppCompat theme (or descendant) with this activity

The Question : 1050 people think this question is useful Android Studio 0.4.5 Android documentation for creating custom dialog boxes: http://developer.android.com/guide/topics/ui/dialogs.html If you want a custom dialog, you can instead display an Activity as a dialog instead of using the Dialog APIs. Simply create an activity and set its theme to Theme.Holo.Dialog in the <activity>

android – What is the difference between match_parent and fill_parent?

The Question : 1421 people think this question is useful I’m a little confused about two XML properties: match_parent and fill_parent. It seems that both are the same. Is there any difference between them? The Question Comments : if you feel free developer.android.com/reference/android/view/… The Answer 1 1246 people think this answer is useful They’re the

What is the difference between gravity and layout_gravity in Android?

The Question : 1367 people think this question is useful I know we can set the following values to the android:gravity and android:layout_gravity properties: center center_vertical center_horizontal, etc. But I am confused regarding both of these. What is the difference between the usage of android:gravity and android:layout_gravity? The Question Comments : Easy trick to remember:

关闭/隐藏Android软键盘

我有一个EditText和Button我的布局。 在编辑栏中写入并单击后Button,我想隐藏虚拟键盘。我认为这是一段简单的代码,但我可以在哪里找到它的一个例子? 答案 您可以强制Android使用InputMethodManager隐藏虚拟键盘,调用hideSoftInputFromWindow,传入含有焦点视图的窗口标记。 // Check if no view has focus: View view = this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } 这将迫使键盘在所有情况下隐藏。在某些情况下,您将希望InputMethodManager.HIDE_IMPLICIT_ONLY作为第二个参数传入,以确保在用户没有明确强制显示时隐藏键盘(通过按住菜单)。 为了澄清这种疯狂,我想首先代表所有Android用户道歉,因为谷歌对软键盘的彻底荒谬处理。对于同样简单的问题,有很多答案各不相同,这是因为与Android中的其他许多API一样,这个API的设计非常糟糕。我可以想到没有礼貌的方式来陈述它。 我想隐藏键盘。我期望为Android提供以下声明:Keyboard.hide()。结束。非常感谢你。但Android有一个问题。您必须使用InputMethodManager隐藏键盘。好的,很好,这是Android的键盘API。但!您需要有一个Context以访问IMM。现在我们有一个问题。我可能希望将键盘从静态或实用类中隐藏起来,这些类没有任何用处或者不需要Context。或者更糟糕的是,IMM要求您指定要隐藏键盘FROM的内容View(甚至更糟糕的是Window)。 这就是隐藏键盘如此具有挑战性的原因。亲爱的Google:当我正在查找蛋糕的食谱时,世界上没有人RecipeProvider会拒绝为我提供配方,除非我首先回答世卫组织,蛋糕将被吃掉,并且它将被吃掉! 这个悲伤的故事以丑陋的真相结束:为了隐藏Android键盘,您将需要提供2种形式的识别:a Context和a View或a Window。 我已经创建了一个静态实用程序方法,可以非常稳定地完成这项工作,只要您从中调用它Activity。 public static void hideKeyboard(Activity activity) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); //Find the currently focused view, so we can grab the correct