2012-02-03 33 views

Trả lời

96

Một ngắn ...

$ grep ActionBar platforms/android-11/data/res/values/* dẫn đến

styles.xml:

<style name="TextAppearance.Widget.ActionBar.Title" 
     parent="@android:style/TextAppearance.Medium"> 
</style> 

<style name="TextAppearance.Widget.ActionBar.Subtitle" 
     parent="@android:style/TextAppearance.Small"> 
</style> 

[…] 

<style name="TextAppearance.Medium"> 
    <item name="android:textSize">18sp</item> 
</style> 

<style name="TextAppearance.Small"> 
    <item name="android:textSize">14sp</item> 
    <item name="android:textColor">?textColorSecondary</item> 
</style> 
+1

Co ol, cảm ơn! Vậy Medium và Small là gì? Ngoài ra, có vẻ như tôi chỉ có thể thay đổi kích thước văn bản trên API 13+, vậy điều này có gây ra sự không thống nhất cho máy tính bảng chạy 3.0 so với 3.2 không? – aimango

+0

styles.xml và themes.xml chứa các định nghĩa Theme và Theme.Holo mặc định. TextAppearance.Medium là một kiểu được đặt tên (với thừa kế, xem http://developer.android.com/guide/topics/ui/themes.html#Inheritance) được định nghĩa bằng cách sử dụng phần tử style. Bạn có thể định nghĩa phong cách Foo.Bar của riêng mình nếu muốn ... Không biết làm thế nào để bạn cố gắng thay đổi kích thước văn bản, tôi khuyên bạn nên xác định phong cách/chủ đề của riêng bạn nếu bạn muốn một số ứng dụng nhìn và cảm nhận nhất quán. Gửi một câu hỏi mới mô tả nhu cầu của bạn là gì và đặt liên kết ở đó;) – Renaud

+0

cảm ơn câu trả lời và đặc biệt là sử dụng lệnh grep – moujib

53

này làm việc cho tôi.

Đây là những gì tôi làm để có được thanh công cụ mặc định phong cách:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/toolbar_top" 
    android:layout_width="match_parent" 
    android:layout_height="?actionBarSize" 
    android:background="@color/primary_dark"> 

    <TextView 
     android:id="@+id/toolbar_title" 
     style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</android.support.v7.widget.Toolbar> 

này lừa để giữ phong cách mặc định style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"

Sau đó, trong hoạt động của bạn, bạn có thể làm:

Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top); 
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title); 
mTitle.setText("Custom..."); 
+0

Hoặc @ style/TextAppearance.Widget.AppCompat.Toolbar.Title – krossovochkin

+0

No. phong cách tồn tại. –

+0

Cảm ơn rất nhiều, đã giúp tôi. –

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