導航:首頁 > APP軟體 > 安卓styleparent

安卓styleparent

發布時間:2024-09-13 07:51:14

A. 安卓編程怎樣自定義menu中的字體大小

一、先到AndroidManifest.xml看看當前的theme是什麼:

比如我這里的是AppTheme

[html] view plain
<application
......
android:theme="@style/MyAppTheme" >

二、然後在資源文件的res/values/styles.xml中找到 你的主題:

[html] view plain
<style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">

三、然後在此添加上一個item,name=android:actionMenuTextAppearance,然後引用你自己定義的文字樣式,不管是大小還是顏色都可以自己定義

[html] view plain
<style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionMenuTextAppearance">@style/MyMenuTextStyle</item>
</style>

<style name="MyMenuTextStyle">
<item name="android:textColor">@android:color/red</item>
<item name="android:textSize">16sp</item>
</style>

B. 如何修改Android App的樣式風格

android中可以自定義主題和風格。風格,也就是style,我們可以將一些統一的屬性拿出來,比方說,長,寬,字體大小,字體顏色等等。可以在res/values目錄下新建一個styles.xml的文件,在這個文件裡面有resource根節點,在根節點裡面添加item項,item項的名字就是屬性的名字,item項的值就是屬性的值,如下所示:
復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
</resources>

style中有一個父類屬性parent, 這個屬性是說明當前的這個style是繼承自那個style的,當然這個style的屬性值中都包含那個屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測試一下效果了,先寫一個布局文件,比如說一個TextView什麼的,可以用到這個style的。這里我就寫一個EditText吧。下面是布局文件:
復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas。android。com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/MyText"
android:text="測試一下下"/>
</LinearLayout>

說完了style,下面就說說Theme,Theme跟style差不多,但是Theme是應用在Application或者Activity裡面的,而Style是應用在某一個View裡面的,還是有區別的,好了,廢話不多說,還是看代碼吧。下面的是style文件:
復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
<style parent="@android:style/Theme" name="CustomTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@drawable/icon</item>
<item name="android:windowBackground">?android:windowFrame</item>
</style>
</resources>

style中有一個父類屬性parent, 這個屬性是說明當前的這個style是繼承自那個style的,當然這個style的屬性值中都包含那個屬性中的,你也可以修改繼承到的屬性的值,好了,style完成了,我們可以測試一下效果了,先寫一個布局文件,比如說一個TextView什麼的,可以用到這個style的。這里我就寫一個EditText吧。下面是布局文件:
復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas。android。com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/MyText"
android:text="測試一下下"/>
</LinearLayout>

說完了style,下面就說說Theme,Theme跟style差不多,但是Theme是應用在Application或者Activity裡面的,而Style是應用在某一個View裡面的,還是有區別的,好了,廢話不多說,還是看代碼吧。下面的是style文件:
復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
<style parent="@android:style/Theme" name="CustomTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@drawable/icon</item>
<item name="android:windowBackground">?android:windowFrame</item>
</style>
</resources>

可以看到這里寫了一個繼承自系統默認的Theme的主題,裡面有3個屬性,這里強調一下第三個屬性的值的問題,這里打個問號,然後加前面的一個item的名字表示引用的是那個名字的值,也就是那個名字對應的圖片。
然後我們在Manifest.xml裡面的Application裡面加一個Theme的屬性,這個屬性對應的就是我們上面寫的Theme。
復制代碼 代碼如下:

<application android:icon="@drawable/icon" android:label="@string/app_name"
android:theme="@style/CustomTheme">
<activity android:name=".TestStyle"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

上面的代碼沒有標題欄,背景和fram都是我們設置的圖片。當然也可以在代碼中設置主題:
復制代碼 代碼如下:

package com.test.shang;
import android.app.Activity;
import android.os.Bundle;
public class TestStyle extends Activity {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.CustomTheme);
setContentView(R.layout.test_style);
}
}

C. 安卓開發Layout XML 下出現這種警告怎麼解決

滑鼠點到黃色來敬告上自就會彈出提示了嘛,類似於這種「
Buttons in button bars should be borderless; use style="?
adt的版本越來越高了,所以也要求規范了,一些屬性官方要求是要寫上的,比如style等,早期android1.5、1.6的時候就沒這么多要求,可能隨後發展這些屬性不寫就不是黃色警告了,就變紅色錯誤了。
解決的方式是給每一個button或者其他控制項加上style樣式。

閱讀全文

與安卓styleparent相關的資料

熱點內容
修路紅頭文件哪裡有 瀏覽:360
spark讀文件夾 瀏覽:850
數據挖掘面試有哪些書 瀏覽:385
網路技術內容有哪些 瀏覽:369
小米手機游戲加速保存的視頻的文件路徑 瀏覽:505
python怎麼關文件 瀏覽:91
什麼網站伺服器好 瀏覽:855
魔獸壓縮文件密碼 瀏覽:145
hlp格式文件轉pdf格式 瀏覽:139
安全模式改開機密碼 瀏覽:241
上傳課堂派的時候怎麼找不到文件 瀏覽:415
科研立項怎麼做數據分析 瀏覽:263
2010excel教程 瀏覽:233
蘋果5s用鑷子開機圖片 瀏覽:272
threejsvertices 瀏覽:616
iphone運營商修改 瀏覽:444
浦東新區數據技術服務電話多少 瀏覽:924
迅雷下載任務配置文件錯誤怎麼辦 瀏覽:220
哪個網站可以畫畫接單 瀏覽:35
編程能幹到什麼程度 瀏覽:279

友情鏈接