2012-09-16 31 views
5

Tôi sử dụng công cụ chọn và tôi không biết cách đặt kích thước văn bản. Có lẽ tôi đang làm một cái gì đó sai - giúpcách đặt cỡ chữ bằng bộ chọn?

arrow.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/button_pressed" android:state_pressed="true" android:color="@color/green"></item> 

</selector> 
+0

Tôi có cùng một câu hỏi với bạn nhưng vẫn không thể tìm ra câu trả lời :) –

Trả lời

-1

Tạo của riêng bạn style.xml và xác định kiểu văn bản. Và sau đó đặt kiểu trong bộ chọn của bạn.

style.xml

<style name="myStyle"> 
    <item name="android:textSize">9px</item> 
    <item name="android:textColor">#fff</item> 
    <item name="android:textStyle">bold</item> 
</style> 

Và trong chọn của bạn

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" 
      style="@style/myStyle" /> 
</selector> 
+0

Hi @Apurva, nơi để đặt các tập tin chọn? Là nó trong drawable? – Elye

+0

@elye có trong drawable tất nhiên – Apurva

+3

Điều này thực sự làm việc? Tôi nhận được cảnh báo "Kiểu thuộc tính không xác định". Bộ chọn AFAIK chỉ hoạt động với các bản vẽ và không phải kiểu. – kalehv

2

Bạn có thể sử dụng một bộ chọn dưới nguồn phim hoạt hình:

<!-- res/animator/text_size.xml --> 
<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_focused="true"> 
     <set> 
      <objectAnimator 
       android:duration="0" 
       android:propertyName="textSize" 
       android:valueTo="18sp" 
       android:valueType="floatType"/> 
     </set> 
    </item> 
    <item android:state_focused="false"> 
     <set> 
      <objectAnimator 
       android:duration="0" 
       android:propertyName="textSize" 
       android:valueTo="10sp" 
       android:valueType="floatType"/> 
     </set> 
    </item> 
</selector> 

Bạn có thể có 0 thời gian cho nhảy thẳng vào giá trị hoặc đặt thời gian ở đó.

Sau đó, để sử dụng nó thiết lập android:stateListAnimator trên quan điểm của bạn:

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button 3" 
    android:stateListAnimator="@animator/text_size"/> 
+0

Điều này rất hữu ích, tuy nhiên tôi thấy rằng việc sử dụng giá trị sp trong objectAnimator 'valueTo/From' làm cho nó được chuyển thành float hai lần vì' TextView.setTextSize (float) 'xử lý giá trị là sp. Không chỉ định một đơn vị sẽ giữ kích thước văn bản phù hợp với phần còn lại của tài nguyên. – Zharf

+0

Tôi không làm theo, có thể viết lên như một câu trả lời. – weston

Các vấn đề liên quan