gpt4 book ai didi

android - 如何在偏好 Activity android上创建自定义窗口标题?

转载 作者:行者123 更新时间:2023-11-29 22:01:09 25 4
gpt4 key购买 nike

在构建应用程序时,有时我们需要创建一个自定义窗口标题来满足我们的需要并使我们的应用程序与众不同。我在通过此代码在首选项 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com