我的UI中大部分元素都引用了字體大小,大小,顏色等的樣式資源。是否可以動態更改其中一個<item>
的值?我希望能夠獲得屏幕的物理尺寸並更改尺寸,使其佔用屏幕尺寸大致相同的屏幕百分比。 <item name="android:textSize">12dp</item>
將去<item name="android:textSize">15dp</item>
用Java更改Android中的XML樣式資源
0
A
回答
0
你的意思是你想要應用不同的屏幕尺寸樣式。
看看這個:http://developer.android.com/guide/practices/screens_support.html
,這將幫助你。
編輯:經過一番研究,我發現了一個可能的答案。
// declaring resources
int mHeight;
int mWidth;
/* I am considering a TextView, if you want,
* you can apply it for any widget you like. */
TextView mTextView = (TextView)findViewById(R.id.your_textview_id);
/* right. now we want to get the screen dimensions. */
Display mDisplay = getWindowManager().getDefaultDisplay();
mHeight = mDisplay.getHeight();
mWidth = mDisplay.getWidth();
/* now we have the values that needed.
* the next thing to do is mathematical operation.
* do this as you wish. the thing I do is obtain a
* value that the mHeight is subtracted by mWidth and divided by 2. */
float mTextSize = (float) (mHeight - mWidth)/2;
// apply it as text size of the TextView.
mTextView.setTextSize(mTextSize);
相關問題
- 1. 更新/改變動畫Android中的XML資源
- 2. 將樣式資源在繪製XML
- 3. 如何以編程方式更改Android中的字符串資源xml值?
- 4. 的Android XML資源格式/結構
- 5. 更改資源(XML字符串)
- 6. 更改android MediaController的樣式
- 7. Android爲Gingebread提供樣式資源
- 8. 使用XPath在Java中使用Android SDK查詢xml資源
- 9. Android應用中的樣式資源相關'小工具'錯誤 -
- 10. WPF - 在樣式中使用ControlTemplate資源
- 11. 使用樣式表資源設計靜態Rails HTML使用樣式表資源
- 12. 如何更改Android中的樣式
- 13. 在FullCalendar中更改資源
- 14. android動態更改樣式
- 15. Android:更改edittext樣式
- 16. Java隱式試用資源
- 17. xmpp資源更改?
- 18. 更改資源值
- 19. Android XML樣式
- 20. Android XML樣式
- 21. ArrayAdapter:根據項目更改資源(Android)
- 22. Android庫中的XML資源衝突
- 23. Android字符串資源中的XML?
- 24. 使用Java國際化修改Wicket的XML資源包(i18n)
- 25. 在Java中更改XML的佈局樣式/將變量添加到XML
- 26. Android XML資源值錯誤
- 27. 從xml解析android資源
- 28. Android - 使用庫項目時的通用樣式資源?
- 29. 用於ASP.NET控件樣式的資源?
- 30. 在java中編輯Android xml資源文件的內容
您不能在運行時更改'資源'。 – codeMagic
:(有沒有類似於文本大小的重量?我有文本視圖的邊界大小縮放很大,我只是需要文本來實際縮放。 – user1971