2012-07-27 81 views
1

我正在解决此问题。我需要在标题栏中设置自定义字体,但我的活动正在使用动态生成的布局(因此不使用setContentView(R.layout.somtehing))。ListActivity中标题栏中的Android自定义字体

我都试过了,那设置自定义字体,标题栏,你可以做到这一点通过这些代码:

type = Typeface.createFromAsset(getAssets(),"fonts/verdanab.ttf"); 
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
    setContentView(R.layout.something); 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.gal_title); 

    title = (TextView) findViewById(R.id.title); 
    title.setText(R.string.Text); 
    title.setTypeface(type); 

问题是,这个代码不工作,应用程序不会看到TextView称号,因为没有setContentView()。任何建议?

THX

+0

我们已经设置使用getWindow()标题布局。setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R .layout.gal_title); – moDev 2012-07-27 08:36:11

+0

这里是真正好的教程,只是为了你所要求的http://www.helloandroid.com/tutorials/how-create-custom-titlebar – Akram 2012-07-27 08:50:11

回答

1

初始化此行type = Typeface.createFromAsset(getAssets(),"fonts/verdanab.ttf");此行

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.gal_title); 

使用此代码后,

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
    setContentView(R.layout.something); 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.gal_title); 

    Typeface type = Typeface.createFromAsset(getAssets(),"fonts/verdanab.ttf"); 
    title = (TextView) findViewById(R.id.title); 
    title.setText(R.string.Text); 
    title.setTypeface(type); 
+1

为什么你低估了我? – moDev 2012-07-27 08:38:28

+1

你再次做了同样的事 – moDev 2012-07-27 08:56:50

+0

我改变了我的答案。 – moDev 2012-07-27 09:10:13