我正在尝试更改android.support.v7.app.AlertDialog标题文本的字体。
方法一:
TextView title = (TextView) dialog.findViewById(android.R.id.title); //returns null
Run Code Online (Sandbox Code Playgroud)
方法二:
final int titleId = context.getResources().getIdentifier("alertTitle", "id", "android");
TextView title = (TextView) dialog.findViewById(titleId); //Also returns null.
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以获得标题TextView?
请注意,我不想使用自定义布局。
谢谢。
我对哈希码知之甚少.我发现这个代码可以打印出碰撞.
你能告诉我什么是碰撞以及如何减少它?我们为什么要使用哈希码?
public static int getHash(String str, int limit)
{
int hashCode = Math.abs(str.hashCode()%(limit));
return hashCode;
}
/**
* @param args
*/
public static void main(String[] args)
{
int hashLimit = 10000;
int stringsLimit = 10000;
String[] arr = new String[hashLimit];
List<String> test = new ArrayList<String>();
Random r = new Random(2);
for ( int i = 0 ; i < stringsLimit ; i++ )
{
StringBuffer buf = new StringBuffer("");
for ( int j = 0 ; j < 10 …Run Code Online (Sandbox Code Playgroud) 我试图在共享首选项中保存一个整数值,并在应用程序重新启动时再次加载它。
我在我的主要活动中创建了一个共享首选项,并尝试在单击菜单项时将整数值保存在另一个菜单侦听器类中。菜单侦听器类位于不同的包中,菜单侦听器类扩展了主活动。
但是当我尝试这样做时,我收到了空指针异常。
我也浏览过这个链接!但这似乎对我没有帮助。
这是我的代码:
主要活动:
protected SharedPreferences mPrefs;
protected SharedPreferences.Editor mEditor;
protected Context main_activityclass_context; //EDIT
public static int count=0;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPrefs = this.getSharedPreferences("THEME", 0);
mEditor = mPrefs.edit();
}
Run Code Online (Sandbox Code Playgroud)
菜单侦听器类:
case mainActivity.MENU_ITEM_THEME_DARK:
{
mainActivity.count=1;
mPrefs =main_activityclass_context.getSharedPreferences("THEME", 0); //EDIT
mEditor = mPrefs.edit();
mEditor.putInt("Theme_count", mainActivity.count).commit();
break;
}
Run Code Online (Sandbox Code Playgroud)
我在 Menu Listener 的行上收到 Null 指针异常:
mPrefs = getSharedPreferences("THEME", 0);
mEditor = mPrefs.edit();
Run Code Online (Sandbox Code Playgroud)
我的日志猫:
08-03 10:54:03.650: E/AndroidRuntime(31258): FATAL EXCEPTION: main
08-03 10:54:03.650: E/AndroidRuntime(31258): java.lang.NullPointerException
08-03 10:54:03.650: …Run Code Online (Sandbox Code Playgroud) 是否可以动态更改操作栏图标?
我把它放在我的清单中.我想改变它并通过代码设置它.
我的清单:
<activity android:name=".plugin.importer.face.FaceActivity"
android:windowSoftInputMode="stateHidden|adjustResize"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.SYNC" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:icon="@drawable/new_enabled">
<action android:name="android.intent.action.INSERT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
有办法吗?
谢谢.
我正在使用此答案中的代码.
但不是为我使用的文本视图设置android:textColor
风格= "?background_text_color_theme"
必须根据应用程序的主题设置文本颜色(黑色主题的白色文本颜色,反之亦然).这适用于除CheckBoxPreference之外的所有其他地方.
我对链接所做的更改:
<TextView android:id="@+android:id/title"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee" android:fadingEdge="horizontal"
style="?background_text_color_theme" />
Run Code Online (Sandbox Code Playgroud)
这是我的style.xml:
<style name="background_text_color_theme_bl">
<item name="android:textColor">#ffffff</item>
</style>
<style name="background_text_color_theme_wh">
<item name="android:textColor">#000000</item>
</style>
Run Code Online (Sandbox Code Playgroud)
的themes.xml:
<style name="Theme.White" parent="@android:style/Theme.Holo.Light">
<item name="background_text_color_theme">@style/background_text_color_theme_wh</item>
</style>
<style name="Theme.Black" parent="@android:style/Theme.Holo">
<item name="background_text_color_theme">@style/background_text_color_theme_bl</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但文字颜色似乎没有根据风格设置.谁能告诉我为什么会这样?
谢谢.