導航:首頁 > 操作系統 > androidvalues文件夾

androidvalues文件夾

發布時間:2025-09-30 00:31:05

android 自定義view 怎麼規定view的樣式

android 自定義view的樣式的實現:

1.在values文件夾下,打開attrs.xml,其實這個文件名稱可以是任意的,寫在這里更規范一點,表示裡面放的全是view的屬性。

2.因為我們下面的實例會用到2個長度,一個顏色值的屬性,所以我們這里先創建3個屬性。

<declare-styleable name="rainbowbar">
<attr name="rainbowbar_hspace" format="dimension"></attr>
<attr name="rainbowbar_vspace" format="dimension"></attr>
<attr name="rainbowbar_color" format="color"></attr>
</declare-styleable>

舉例說明:

藍色的進度條

public class RainbowBar extends View {

//progress bar color
int barColor = Color.parseColor("#1E88E5");
//every bar segment width
int hSpace = Utils.dpToPx(80, getResources());
//every bar segment height
int vSpace = Utils.dpToPx(4, getResources());
//space among bars
int space = Utils.dpToPx(10, getResources());
float startX = 0;
float delta = 10f;
Paint mPaint;

public RainbowBar(Context context) {
super(context);
}

public RainbowBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public RainbowBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
//read custom attrs
TypedArray t = context.obtainStyledAttributes(attrs,
R.styleable.rainbowbar, 0, 0);
hSpace = t.getDimensionPixelSize(R.styleable.rainbowbar_rainbowbar_hspace, hSpace);
vSpace = t.getDimensionPixelOffset(R.styleable.rainbowbar_rainbowbar_vspace, vSpace);
barColor = t.getColor(R.styleable.rainbowbar_rainbowbar_color, barColor);
t.recycle(); // we should always recycle after used
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setColor(barColor);
mPaint.setStrokeWidth(vSpace);
}

.......
}

View有了三個構造方法需要我們重寫,這里介紹下三個方法會被調用的場景,

第一個方法,一般我們這樣使用時會被調用,View view = new View(context);

第二個方法,當我們在xml布局文件中使用View時,會在inflate布局時被調用,
<View layout_width="match_parent" layout_height="match_parent"/>。

第三個方法,跟第二種類似,但是增加style屬性設置,這時inflater布局時會調用第三個構造方法。
<View style="@styles/MyCustomStyle" layout_width="match_parent" layout_height="match_parent"/>。

Ⅱ android開發中怎麼設置多語言版本

android多語言實現必須是將strings.xml放在不同的文件夾目錄下,由安卓系統自動去載入文字資源。

1.Android 中要實現國際化比較簡單,字元串國際化:只要在 res 文件夾下新建對應語言的 values 文件夾就好了。

例如:

  1. 英語環境下的,文件夾命名為:values-en

  2. 美國英文環境:values-en-rUS

  3. 中文環境為:values-zh

  4. 大陸地區中文環境:values-zh-cn


2.eclipse 下新建 Android 項目時,會在 res 目錄下自動創建一個默認語言環境的文件夾 : values 。

3.當某一個資源沒有在語言環境的對應的資源集合中找到時,就會使用 values 下的資源。若某一個語言環境沒有在項目中定義語言環境,那麼也會使用 values 下的資源。

閱讀全文

與androidvalues文件夾相關的資料

熱點內容
bz2解壓效率 瀏覽:101
打開兩個命令窗口 瀏覽:109
創有編譯器怎麼在商店裡生成武器 瀏覽:61
officewordpdf 瀏覽:607
怎麼知道汽車安卓屏的品牌 瀏覽:844
linux文件組許可權設置 瀏覽:154
棋牌源碼轉讓交易手續 瀏覽:712
安卓手機如何打開fsn文件 瀏覽:276
為什麼nba2k21沒有安卓 瀏覽:333
程序員難問題 瀏覽:638
壓縮面膜怎麼打開 瀏覽:188
深圳程序員談梅州 瀏覽:436
電腦檢測伺服器怎麼弄 瀏覽:725
androidvalues文件夾 瀏覽:154
中國程序員出海 瀏覽:527
全書pdf下載 瀏覽:154
百家號app個人主頁在哪裡 瀏覽:468
編譯原理傳地址傳值傳名 瀏覽:337
java的瀏覽功能 瀏覽:274
張岩李秀數據結構與演算法第五版 瀏覽:114