TextView¶
TextViewにフォントサイズを下げて表示する¶
ア.表示例


イ.以下の方法を参考する
textViewに全表示の場合、フォントが26、桁数が15 15桁以上になる場合、フォントサイズを下げて表示する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | /** * Set the sum of the sub total and the PaymentTotal */ private void setAllSubTotal() { // Get all the sub total TextView textViewAllSubTotal = (TextView) this .findViewById(R.id.textViewAllSubTotal); Long allSubTotal = getAllSubTotal(); String allTotal = RegisterCurrencyFormat.format(allSubTotal); textViewAllSubTotal.setText(allTotal); int fonSize = 26; if (15 < allTotal.length()) { //getFontSize()メソッドを呼び出す fonSize = getFontSize(allTotal, textViewAllSubTotal.getPaint()); } textViewAllSubTotal.setTextSize(fonSize); // Set the PaymentTotal setPaymentTotal(); } /** * Re size the font so the specified text fits in the text box * assuming * the text box is the specified width. */ private int getFontSize(final String text, Paint textPaint) { int minSize = MIN_FONT_SIZE; int maxSize = MAX_FONT_SIZE; Paint paint = new Paint(); paint.set(textPaint); float maxWidth = PX_TEXTVIEW_MAX_WIDTH; // width's px value int trySize = maxSize; paint.setTextSize(trySize); float measure = paint.measureText(text); while ((minSize < trySize) && (maxWidth < measure)) { trySize -= 1; if (trySize <= minSize) { trySize = minSize; break; } paint.setTextSize(trySize); measure = paint.measureText(text); } return trySize; } |
ウ.参考ソース:InDrawer841(在高登録)
TextViewの左、右、上、下にアイコンの付ける¶
1.xmlにアイコンを付けています
1 2 3 4 5 6 7 8 9 10 11 | Drawable tagIcon; Resource res=context.getResources(); tagIcon=res.getDrawable(comTag.getBigIntTag(tagCon.getColor())); tagIcon.setBounds(0,0,tagIcon.getMinimumWidth(),tagIcon.getMinimumHeight()); //tagIcon:アイコン標識 //①: 左アイコン //②: 上アイコン //③: 右アイコン //④: 下アイコン holder.textViewTagName.setCompoundDrawables(①,②,③,④); holder.textViewTagName.setText(tagCon.getName()); |
2.アプリリソースに付ける時、以下の方法を使う
1 2 3 4 5 6 7 8 9 10 | <TextView android:id="@+id/textViewMarkTime" style="@style/style_textview" android:layout_width="wrap_content" android:layout_height="34dp" android:drawableLeft="@drawable/icon_time" android:drawableTop="@drawable/icon_time" android:drawableRight="@drawable/icon_time" android:drawableBottom="@drawable/icon_time" android:gravity="center"/> |
文字入力パネルの制御について¶
Androidのキーボード制御方式: 方法1(入力メソッドのウィンドウが既に表示されている場合、隠しファイル、およびその逆の表示):
1 2 | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); |
方法2(ソフトキーボード入力の表示を受け入れる表示、SHOW_FORCED力ディスプレイ)
1 2 | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(view,InputMethodManager.SHOW_FORCED); |
方法3 (隠されたシステムのデフォルトの入力メソッドのコール)
1 2 | ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); // (WidgetSearchActivityは現在のActivity) |
★方法4 (EditTextの外をクリックして、キーボードを隠す)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | /** * 画面タッチ動作 */ @Override public boolean dispatchTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { View v = getCurrentFocus(); if (isShouldHideInput(v, ev)) { hideSoftInput(v.getWindowToken()); } } return super.dispatchTouchEvent(ev); } /** * 画面の位置をクリックして、キーボードを隠す * * @param v * ビュー * @param event * イベント * @return true:表示 false:隠す */ private boolean isShouldHideInput(View v, MotionEvent event) { if (v != null && (v instanceof EditText)) { int[] position = { 0, 0 }; v.getLocationInWindow(position); int left = position[0]; int top = position[1]; int bottom = top + v.getHeight(); int right = left + v.getWidth(); if (left < event.getX() && event.getX() < right && top < event.getY() && event.getY() < bottom) { return false; } else { return true; } } return false; } /** * キーボードを隠す * * @param token */ private void hideSoftInput(IBinder token) { if (token != null) { InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); im.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS); } } |
ColorTextView/AutoSizeTextViewについて¶
ColorTextViewの使用方法¶
VXレジシリーズのプログラムの作成中で、ListViewのフォーカス行に LayoutBarというデザインがありますが、 アイテムをクリックすると、背景色を反転するという要求もあります。

そこでColorTextViewを対応します。 下記の手順より参照してください。
【手順】
- ListViewのItemレイアウトの定義で、背景色反転するアイテムのみ、ColorTextViewにしてください。

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

- Adapter:getViewメソッドを下記に設定してください。

フォーカス行のどこでもクリックしたら、特定項目をクリックすると見られるとき

getviewメソッドに下記の設定をしてください。
【注意】:textViewAttributeのXMLプロパティに反転機能を設定しないでください%

- Activity:Dialogから戻るメソッドで、Adapterのリフレッシュを行ってください。

AutoSizeTextViewについて¶
AutoSizeTextViewを使っている場合は、上記と同じのほか 下記のXMLプロパティを追加してください。
