2015-11-23 47 views
2

我正在開發一款適用於Android的軟鍵盤,目的是擴展現在停用的原始8pen鍵盤。
我有基本的結構工作,現在想要使鍵盤的大小用戶可配置。
有沒有一種方法來配置Android軟鍵盤的高度和寬度

有沒有辦法配置鍵盤的高度和寬度?
因爲有幾個人問我的代碼看起來像下面是一個片段,並充分最新的版本可以在這裏找到 - >8Vim

public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 

    /*Logging stuff*/ 
    int width = View.MeasureSpec.getSize(widthMeasureSpec); 
    int height = View.MeasureSpec.getSize(heightMeasureSpec); 
    /*Various other Stuff*/ 
    radius = (0.325f * width)/2; 
    centre = new PointF((width/2),(height/2)); 
    circle = new Circle(centre, radius); 
    // Set the new size because the "onMeasure" contract so specifies 
    setMeasuredDimension(width, height); 
    Logger.v(this, "onMeasure returns"); 
} 

UPDATE:

所以我已經找到InputServiceMethod類有一個名爲getMaxWidth()的方法,如果我在我的視圖類(負責顯示鍵盤)中將鍵盤的寬度設置得小於此值,則鍵盤右側的剩餘區域變黑並且不再可用。

我得到的想法,如果我改變視圖類本身的鍵盤的高度,我可能能夠實現我在​​找什麼,但...是否有可能改變視圖的高度上用戶的奇想?任何建議/想法/經驗值得歡迎。

回答

0

在這裏你去,使用的代碼,它只是你想要什麼

mRootWindow = getWindow(); 
mRootView = mRootWindow.getDecorView().findViewById(android.R.id.content); 
mRootView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() { 
public void onGlobalLayout(){ 
    Rect r = new Rect(); 
    View view = mRootWindow.getDecorView(); 
    view.getWindowVisibleDisplayFrame(r); 
    // r.left, r.top, r.right, r.bottom 
} 
}); 
+1

如此有效,我需要配置「Rect r」,它會顯示出來嗎? 就我看來,我不需要在我的視圖中弄亂「onMeasure」功能嗎? – flide

+0

好吧,你還沒有發佈你的代碼。而這東西爲朋友工作 – johnrao07

+0

更新了問題,並添加了代碼...不知道這是否會有所幫助.. – flide

0

如果我沒有記錯的話,你想知道的軟鍵盤的Android手機的高度和寬度,然後點擊此鏈接,可能幫你。 Is there any way in android to get the height of virtual keyboard of device

+0

您提到的鏈接是應用程序檢測軟鍵盤是否打開,以及至多我可以得到的是鍵盤的當前大小,但它沒有說明如何設置它... 我的應用程序是一個鍵盤,並且想要動態改變鍵盤的高度和寬度。 – flide

相關問題