我有一个以下问题.我想在列表中自定义行的外观,但在膨胀期间抛出异常.
style.xml中的一段代码
<style name="AppTheme.Main">
<item name="item_shadowColor">#000000</item>
</style>
<style name="item_label">
<item name="android:shadowColor">?attr/item_shadowColor</item>
</style>
Run Code Online (Sandbox Code Playgroud)
attr.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="item_shadowColor" format="color" />
</resources>
Run Code Online (Sandbox Code Playgroud)
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@id/title"
style="@style/item_label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
而且例外
FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at ru.mts.goodok.adapter.CategoryListAdapter.getView(CategoryListAdapter.java:30)
at android.widget.AbsListView.obtainView(AbsListView.java:2052)
at android.widget.ListView.makeAndAddView(ListView.java:1820)
at android.widget.ListView.fillDown(ListView.java:672)
at android.widget.ListView.fillFromTop(ListView.java:732)
at android.widget.ListView.layoutChildren(ListView.java:1673)
at android.widget.AbsListView.onLayout(AbsListView.java:1882) …Run Code Online (Sandbox Code Playgroud) 我有以下问题.我在mapview上绘制路线,在这个单独的线程中:
public void drawRoute(final MapView mapView) {
new Thread(new Runnable() {
public void run() {
try {
//Do something useful
} catch (SomeException se) {
Handler handler = mapView.getHandler();
handler.post(/*show error in UI thread*/)
}}
}).start();
}
Run Code Online (Sandbox Code Playgroud)
但是当我得到处理程序时它返回null,尽管在调试模式处理程序返回并显示错误消息.问题是什么?
PS可能是获取Handler的错误方法,但我无法找到有关它的信息.
我想编写一个自定义字体提供程序来在应用程序之间共享字体.据我所知,文档字体提供程序应作为单独的应用程序安装:
字体提供程序是检索字体的应用程序
但是如何在用户设备上安装此应用程序?明确要求用户从Google Play安装它?用户体验似乎不是很好.
我读到用ui保留片段和视图引用会导致内存泄漏.比我用片段创建测试应用程序,我在视图上存储一些引用并设置setRetaineInstance(true),但是几个屏幕旋转不会导致任何泄漏.MAT说我只有一个父活动实例.我做错了什么?在哪些情况下用ui保留片段会导致泄漏?
RetainInstanceActivity.java
public class RetainInstanceActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, RetainFragment.newInstance())
.commit();
}
}}
Run Code Online (Sandbox Code Playgroud)
RetainFragment.java
public class RetainFragment extends Fragment {
private View mLogin;
private View mPassword;
private View ImageView;
public static RetainFragment newInstance() {
final RetainFragment fragment = new RetainFragment();
return fragment;
}
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container, final Bundle savedInstanceState) {
final …Run Code Online (Sandbox Code Playgroud) 那里.我需要与https://free.temafon.ru建立https连接,但我在Android 2.3及更低版本上有CertPathValidatorException.我做了什么.
Init ssl上下文:
final KeyStore keystore = KeyStore.getInstance("BKS");
keystore.load(getResources().openRawResource(R.raw.temafon),
"W0d3Uoa5PkED".toCharArray());
final TrustManager trustManager = new TemafonTrustManager(keystore);
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { trustManager }, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext
.getSocketFactory());
Run Code Online (Sandbox Code Playgroud)
在这里,我使用自定义TrustManager,因为服务器以错误的顺序发送证书.
这段代码在Android 4.0上工作正常,但2.3在 java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.我正在做的事情上失败了吗?
我已经创建了一个测试项目,可以在这里找到.
AlertDialog源代码有以下方法:
static int resolveDialogTheme(Context context, int resid) {
if (resid == THEME_TRADITIONAL) {
return com.android.internal.R.style.Theme_Dialog_Alert;
} else if (resid == THEME_HOLO_DARK) {
return com.android.internal.R.style.Theme_Holo_Dialog_Alert;
} else if (resid == THEME_HOLO_LIGHT) {
return com.android.internal.R.style.Theme_Holo_Light_Dialog_Alert;
} else if (resid == THEME_DEVICE_DEFAULT_DARK) {
return com.android.internal.R.style.Theme_DeviceDefault_Dialog_Alert;
} else if (resid == THEME_DEVICE_DEFAULT_LIGHT) {
return com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog_Alert;
} else if (resid >= 0x01000000) { // start of real resource IDs.
return resid;
} else {
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(com.android.internal.R.attr.alertDialogTheme,
outValue, true);
return outValue.resourceId;
} …Run Code Online (Sandbox Code Playgroud)