在构建应用程序时,有时我们需要创建一个自定义窗口标题来满足我们的需要并使我们的应用程序与众不同。我在通过此代码在首选项 Activity 上创建图标窗口标题时遇到问题:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_LEFT_ICON);
addPreferencesFromResource(R.layout.setting);
setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.setting);
}
谁能帮帮我?
最佳答案
public class Preferences extends PreferenceActivity {
protected ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main_tab);
title = (TextView) findViewById(R.id.img);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.sc01);
int width=30;
int height=20;
Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp, width, height, true);
this.img.setImageBitmap(resizedbitmap);
}
}
///////In title_bar.xml///////
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="3dp">
</ImageView>
</RelativeLayout>
关于android - 如何在偏好 Activity android上创建自定义窗口标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11893851/