Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
Android 提供了 windowSoftInputMode 屬性來控制輸入法軟鍵盤窗口和 Activity 主窗口的交互,分為 窗口尺寸調整系列 和 輸入法軟鍵盤顯示控制系列。
窗口尺寸調整系列:
該系列參數用來控制當軟鍵盤彈起時,Activity 主窗口的調整策略,因為如果不調整主窗口,很可能會導致當前輸入的控件被軟鍵盤遮擋。
adjustPan:
Activity的主窗口并不會重新調整大小來為輸入法騰出空間,而是窗口的內容會自動上下晃動來保證當前獲得焦點的控件不會被鍵盤遮擋住,然后用戶可以看見自己輸入的內容。相比于 adjustResize 模式而言,它并不是很令人滿意,因為用戶必須關閉輸入法來和被輸入法遮擋住的控件進行交互。
adjustResize:
Activity的主窗口會重新調整大小來為輸入法騰出空間。
adjustUnspecified:
當前模式并不會明確指定 Activity 使用adjustPan 或者 adjustResize ,系統會自動選擇一個模式,選擇結果是,如果當前 Activity 的 Window 中,有可以滾動自身內容的控件,比如 ScrollView,那么選擇結果就是 adjustResize,因為它認為滾動可以使 Window 中的內容即使在一個很小的區域中也可以被看見。Activity 的默認模式就是這個模式。
adjustNoting:
Activity 的 Window 沒有任何變化。
兩種模式下,屏幕 - 主窗口 - 主窗口內容 - 軟鍵盤 的關系如下:
具體效果如下:
沒有滾動內容,adjustPan:
沒有滾動內容,adjustResize:
沒有滾動內容,adjustUnspecified == adjustPan
有滾動內容(ScrollView),adjustPan
有滾動內容(ScrollView),adjustResize
有滾動內容(ScrollView),adjustUnspecified == adjustResize
輸入法軟鍵盤顯示控制系列:
該系列參數用來控制當一個包含 Window 的事物(Activity、Dialog等)展示在屏幕最前端時,軟鍵盤的顯示或者隱藏策略。
stateUnspecified:
系統根據當前具體情況,選擇相應的模式。
stateUnchanged:
軟鍵盤保持它的上一個狀態(上一個Activity 或者 Dialog 在屏幕最前端時,軟鍵盤的狀態),不做變化,不管上一個狀態是顯示還是隱藏。
stateHidden:
當用戶主動進入當前界面時,軟鍵盤隱藏。離開上一個 界面,返回當前界面,不能算作 “主動進入”。被動進入時,保持上一個狀態。
stateAlwaysHidden:
只要是用戶進入該界面,就隱藏軟鍵盤,不管是主動進入(新啟動該界面),還是被動進入(離開上一個界面,返回到當前界面)。
stateVisible:
當用戶主動進入當前界面時,顯示軟鍵盤。離開上一個 界面,返回當前界面,不能算作 “主動進入”。被動進入時,保持上一個狀態。
stateAlwaysVisible:
只要是用戶進入該界面,就顯示軟鍵盤,不管是主動進入(新啟動該界面),還是被動進入(離開上一個界面,返回到當前界面)。
關于某些華為手機的一個Bug
今天遇到一個Bug,是這樣的,在某些華為手機上面,除了第一次點擊輸入框,adjustPan 參數會生效(軟鍵盤可以正常彈起輸入框),后面從第二次開始,怎么點擊,adjustPan 參數都無效。
布局模型大致如下:
[html] view plain copy print?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="cn.hjf.inputtest.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="#2b532b"/>
<EditText
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@null"
android:gravity="center"
android:inputType="numberDecimal"
android:maxLength="8"
android:minWidth="60dp"
android:padding="5dp"
android:text="0.00"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
<RelativeLayout
效果是這樣的:
經過漫長時間的排除(很辛苦),終于找到了Bug的觸發臨界點,就是下面這兩句話:
[html] view plain copy print?
android:gravity="center"
android:inputType="numberDecimal"
android:gravity="center"
又經過了漫長時間的驗證,得出一個結論:在某些華為機型上面,在這種布局模型下,EditText 中如果設置了 inputType 參數(不為 none),那么,在 gravity 取值為某些值得時候,會導致該問題的發生。大致情況如下:
紅色表示失效,綠色表示有效(可以正常工作)。當這兩個參數不指定的時候,可以工作,因為這兩個屬性默認值的組合是可以工作的,上圖中的藍色塊。(備注:沒有完全匹配所有情況,如有相似情況,可以按需匹配,查看結果)
在源碼中可以找到這兩個屬性的默認值:
attrs.xml
[html] view plain copy print?
<!-- Default EditText style. -->
<attr name="editTextStyle" format="reference" />
<!-- Default EditText style. -->
themes.xml
[html] view plain copy print?
<item name="editTextStyle">@style/Widget.EditText</item>
<item name="editTextStyle">@style/Widget.EditText</item>
styles.xml
[html] view plain copy print?
<style name="Widget.EditText">
<item name="focusable">true</item>
<item name="focusableInTouchMode">true</item>
<item name="clickable">true</item>
<item name="background">?attr/editTextBackground</item>
<item name="textAppearance">?attr/textAppearanceMediumInverse</item>
<item name="textColor">?attr/editTextColor</item>
<item name="gravity">center_vertical</item>
<item name="breakStrategy">simple</item>
<item name="hyphenationFrequency">normal</item>
</style>
<style name="Widget.EditText">
attrs.xml
[html] view plain copy print?
<!-- The type of data being placed in a text field, used to help an
input method decide how to let the user enter text. The constants
here correspond to those defined by
{@link android.text.InputType}. Generally you can select
a single value, though some can be combined together as
indicated. Setting this attribute to anything besides
<var>none</var> also implies that the text is editable. -->
<attr name="inputType">
<!-- There is no content type. The text is not editable. -->
<flag name="none" value="0x00000000" />
..........
<!-- The type of data being placed in a text field, used to help an
[java] view plain copy print?
/**
* Special content type for when no explicit type has been specified.
* This should be interpreted to mean that the target input connection
* is not rich, it can not process and show things like candidate text nor
* retrieve the current text, so the input method will need to run in a
* limited "generate key events" mode, if it supports it. Note that some
* input methods may not support it, for example a voice-based input
* method will likely not be able to generate key events even if this
* flag is set.
*/
public static final int TYPE_NULL = 0x00000000;
/**
一個需求
遇到一個需求,大致模型為:有一個界面,里面有一個 輸入框 和 兩個按鈕,分別控制輸入框中數字的加減,如下圖所示:
每次輸入框數字變化,不管是手動輸入還是按鈕控制,都會出發刷新工作,刷新時會彈出一個對話框。
然后需求是這樣的,當手動輸入的時候,這時觸發刷新時,輸入法是顯示的,但是對話框顯示然后消失后,輸入法就被隱藏了。當用按鈕控制的時候,是沒問題的,因為整個過程,輸入法都是隱藏的。所以需求就是,在對話框顯示然后消失后,輸入法能保持出發刷新時的狀態。
解決問題:當把當前 Activity 設置為 stateUnchanged 的時候,并沒有達到理想的效果,因為dialog所在的window,沒有設置該屬性,所以需要把dialog的window也設置為stateUnchanged,方法為:
[java] view plain copy print?
getWindow().setSoftInputMode()
天這篇文章我們主要來看一下表單的控件都有哪些,如何使用表單標簽,與用戶交互。
(1)網站怎樣與用戶進行交互?
答案是使用HTML表單(form)。表單是可以把瀏覽者輸入的數據傳送到服務器端,這樣服務器端程序就可以處理表單傳過來的數據。
使用語法:<form method="傳送方式" action="服務器文件"></form>
詳細講解:
1、<form> :<form>標簽是成對出現的,以<form>開始,以</form>結束。
2、action :瀏覽者輸入的數據被傳送到的地方,比如一個PHP頁面(save.php),后臺可以通過這個文件來接收前端傳過去的數據資料并進行分析處理。
3、method : 數據傳送的方式(get/post),get多用于獲取數據,post多用于提交數據(關于這一塊大家可以簡單了解一下即可,后期我們會在網站制作的時候進行講解)。
注意:所有表單控件(文本框、文本域、按鈕、單選框、復選框等)都必須放在 <form></form> 標簽之間(否則用戶輸入的信息可提交不到服務器上哦!)。
(2)表單控件介紹
1)文本輸入框、密碼輸入框
當用戶要在表單中鍵入字母、數字等內容時,就會用到文本輸入框。文本框和密碼框只有type類型的區別,其它的寫法是一樣的。
使用語法:
文本輸入框:<input type="text" name="文本名稱" value="文本內容" placeholder="文本提示信息" />
密碼輸入框:<input type="password" name="密碼名稱" value="密碼信息" placeholder="密碼提示信息" />
詳細講解:
1、type:當type="text"時,輸入框為文本輸入框,輸入的文字是可以看見的;當type="password"時, 輸入框為密碼輸入框,輸入的文字內容是無法看見的。
2、name:為文本框/密碼框命名,以備后臺程序使用。
3、value:為文本輸入框輸入的內容。
4、placeholder:當我們的value內容為空的時候顯示,用于提示輸入框輸入信息格式;
使用練習:我們創建一個表單,表單里邊包含用戶名和密碼輸入框。具體的代碼如下圖所示:
在網頁中的顯示效果如下所示:
2)多行文本輸入框
上邊文本輸入框用于輸入單行的文本內容,當用戶需要在表單中輸入大段文字時,需要用到文本輸入域。
使用語法:<textarea rows="行數" cols="列數" placeholder="多行文本提示信息" >文本</textarea>
詳細講解:
1、<textarea>標簽是成對出現的,以<textarea>開始,以</textarea>結束。
2、cols:用于控制多行輸入域的列數,rows :用于控制多行輸入域的行數。
3、placeholder:當我們的textarea內容為空的時候顯示,用于提示輸入框輸入信息格式;
使用練習:我們創建一個新的表單,表單里邊包含用戶名和密碼輸入框和用戶個人簡介多行輸入框。具體的代碼如下圖所示:
我們再網頁中的顯示效果就如下圖所示:
好了,本篇文章就先給大家介紹這兩個表單控件的語法以及使用,下篇文章我們將介紹下拉框、選擇框、多選框的語法及使用,記得要多加練習才是王道。
每日金句:把每一件簡單的事做好就是不簡單;把每一件平凡的事做好就是不平凡。喜歡我的文章的小伙伴記得關注一下哦,每天將為你更新最新知識。
:想了解input和label請參看我寫的文【207】點我進入【207】
一、button。
<button>是按鈕標簽,<input type="button" />也是按鈕標簽,它們之間的區別就是button更加強大,它除了可以包含文本之外,還可以包含格式化的文本和圖像,這就是它的強大所在,下面展示它的圖片按鈕功能,當然我畫的按鈕很丑,別介意。
圖1
圖2
這里隨便講講button標簽的四個常用屬性。
圖3
圖4
圖5
二、select。
select是列表和下拉菜單,select不能一個人戰斗,它需要option的配合。
圖6
圖7
disable是禁用的意思。
圖8
圖9
optgroup可以對option進行分組。
圖10
圖11
selected初始被選中的項,開始時默認選中菠蘿。
圖12
圖13
*請認真填寫需求信息,我們會在24小時內與您取得聯系。