Android 如何在关于手机界面添加个图片
前言
欢迎大家我分享和推荐好用的代码段~~
声明
欢迎转载,但请保留文章原始出处:
CSDN:http://www.csdn.net
雨季o莫忧离:http://blog.csdn.net/luckkof
正文
需要在设置-->关于手机 界面定制一个界面类似下图。即需要在preference_srceen中添加图片。
[SOLUTION]
1:在Setting的source code的
src\com\android\settings
文件中添加一个类LogoPreference.java
文件内容如下:
package com.android.settings;
import android.content.Context;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
public class LogoPreference extends Preference {
/**
* @param context
* @param attrs
* @param defStyle
*/
public LogoPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
* @param context
* @param attrs
* @param defStyle
*/
public LogoPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
/**
* @param context
* @param attrs
*/
public LogoPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
* @param context
* @param attrs
*/
public LogoPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
/**
* @param context
*/
public LogoPreference(Context context) {
super(context);
init();
}
* @param context
*/
public LogoPreference(Context context) {
super(context);
init();
}
private void init() {
setLayoutResource(R.layout.logo_preference_layout);
}
@Override
public View getView(View convertView, ViewGroup parent) {
View view = super.getView(convertView, parent);
return view;
}
setLayoutResource(R.layout.logo_preference_layout);
}
@Override
public View getView(View convertView, ViewGroup parent) {
View view = super.getView(convertView, parent);
return view;
}
}
2,在Setting的res\layout目录下添加一个对应的
logo_preference_layout.xml文件。
文件内容如下:
<?xml version="1.0" encoding="utf-8" ?>
-
<
LinearLayout
xmlns:android
="
http://schemas.android.com/apk/res/android
"
android:layout_width
="
match_parent
"
android:layout_height
="
200dip
"
android:minHeight
="
?android:attr/listPreferredItemHeight
"
android:orientation
="
vertical
"
android:gravity
="
center_vertical
">
<
ImageView
android:id
="
@+android:id/icon
"
android:layout_width
="
300dip
"
android:layout_height
="
200dip
"
android:paddingStart
="
0dip
"
android:paddingEnd
="
0dip
"
android:layout_gravity
="
center_vertical
"/>
-
<
RelativeLayout android:id
="
@+android:id/text_layout
"
android:layout_width
="
0dip
"
android:layout_height
="
0dip
"
android:paddingStart
="
0dip
"
android:paddingEnd
="
0dip
"
android:gravity
="
center_vertical
"
android:layout_weight
="
1
"
android:focusable
="
true
"
android:background
="
@drawable/list_selector_holo_dark
">
<
TextView
android:id
="
@+android:id/title
"
android:layout_width
="
0dip
"
android:layout_height
="
wrap_content
"
android:focusable
="
true
"
android:singleLine
="
true
"
android:textAppearance
="
?android:attr/textAppearanceMedium
" />
<
TextView
android:id
="
@+android:id/summary
"
android:layout_width
="
0dip
"
android:layout_height
="
wrap_content
"
android:layout_below
="
@android:id/title
"
android:layout_alignStart
="
@android:id/title
"
android:textAppearance
="
?android:attr/textAppearanceSmall
"
android:maxLines
="
2
" />
</
RelativeLayout
>
</
LinearLayout
>
3:在Setting的device_info_settings.xml中添加一个LogoPreference
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/about_settings">
<
com.android.settings.LogoPreference android:key="jasonAAA
"
android:icon
="
@drawable/pic_indicator
" />
重新编译Setting并push到手机中可以看到上图的效果,如果贵司要更改为自己公司的Logo图片,
只需修改
android:icon
="
@drawable/
pic_indicator为贵司自己
公司的Logo图片即可。