我的android源代码设置为min sdk版本11,目标sdk是17.
这个命令不会在api 11下运行:
getActionBar().setHomeButtonEnabled(true);
Run Code Online (Sandbox Code Playgroud)
据我了解pre api 14,主页按钮自动启用.但是我的来源再次出现在api 11上,我希望它可以继续运行.我如何设置这个如果用户有软糖,那么我可以为他们启用主页按钮?或者我能以某种方式在xml中执行此操作吗?
我已经使用targetapi注释尝试了以下内容:
@TargetApi(14)
public void yourMethod() {
if (android.os.Build.VERSION.SDK_INT >= 14) {
getActionBar().setHomeButtonEnabled(false);
}
}
Run Code Online (Sandbox Code Playgroud)
但仍然无法识别setHomeButtonEnabled.我需要反思才能让它发挥作用吗?
我有一个带有imageview和textview的自定义listview。我想当用户选择一个项目时,textview颜色应该更改,而所有其他textview应该保留默认值。
这是我的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="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listViewBell"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:choiceMode="singleChoice"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<TextView
android:id="@+id/txt_bell_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/rihanna_love_the_way_lie"
android:textColor="@color/black"
android:textSize="15sp"
android:textStyle="bold"
android:typeface="sans" />
<ImageView
android:id="@+id/list_bell_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/bronze_bell" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 只是一个非常简单的问题,在Java中,如果我将我的类的实例设置为全局变量,例如:
MyClass mc = new MyClass();
Run Code Online (Sandbox Code Playgroud)
如果我稍后在代码中为其分配了一个新的类实例:
mc = new MyClass();
Run Code Online (Sandbox Code Playgroud)
该类的旧实例会发生什么,它会导致内存泄漏吗?这是不好的做法吗?
干杯.
我一直试图让我的应用程序在手机响铃时停止播放音乐,但它无法正常工作.我已经尝试了一切,但似乎不可能.这是代码.
package com.beanie.samples.streaming;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import com.beanie.samples.streaming.R;
import com.beanie.samples.streaming.MyService;
import android.app.Activity;
import android.app.IntentService;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
public class HomeActivity extends Activity implements OnClickListener {
private static final …Run Code Online (Sandbox Code Playgroud) 我有这样的喜好:
settings.xml中:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/sectionOneTitle" >
<EditTextPreference
android:title="@string/setModuleName"
android:summary="@string/setModuleNameSum"
android:key="moduleID"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/sectionTwoTitle" >
<EditTextPreference
android:title="@string/setPhoneNumber"
android:summary="@string/setPhoneNumberSum"
android:key="phoneNumber"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/sectionThreeTitle" >
<CheckBoxPreference android:title="@string/setSmsSend"
android:key="setSmsSend" android:summary="@string/setSmsSendSum" />
</PreferenceCategory>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
设置活动
public class SettingsActivity extends PreferenceActivity {
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我需要在设置或取消设置复选框时调用我的MAINActivity中的方法.这可能吗?
谢谢
所以,我有xml布局,并且没有错误,甚至graphical preview视图显示了布局的外观,但是当我调用使用此布局的活动时,我收到一些错误,我不知道如何处理......
这是 XML:
\n\n<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"\n android:layout_width="match_parent"\n android:layout_height="match_parent"\n android:fillViewport="true" >\n\n <RelativeLayout\n android:layout_width="match_parent"\n android:layout_height="wrap_content"\n android:paddingBottom="@dimen/activity_vertical_margin"\n android:paddingLeft="@dimen/activity_horizontal_margin"\n android:paddingRight="@dimen/activity_horizontal_margin"\n android:paddingTop="@dimen/activity_vertical_margin" >\n\n <RelativeLayout\n android:id="@+id/rlTopNumara"\n android:layout_width="match_parent"\n android:layout_height="wrap_content"\n android:padding="16dp" >\n\n <TextView\n android:id="@+id/tvNamePickNumara"\n android:layout_width="wrap_content"\n android:layout_height="wrap_content"\n android:layout_alignParentLeft="true"\n android:layout_centerVertical="true"\n android:paddingLeft="16dp"\n android:text="@string/lottery_ticket_application"\n android:textSize="32sp"\n android:textStyle="bold" />\n\n <ImageView\n android:id="@+id/ivHomePickNumara"\n android:layout_width="wrap_content"\n android:layout_height="wrap_content"\n android:layout_alignParentRight="true"\n android:paddingRight="16dp"\n android:src="@drawable/home" />\n </RelativeLayout>\n\n <RelativeLayout\n android:id="@+id/rlOnNumara1DateTop"\n android:layout_width="match_parent"\n android:layout_height="wrap_content"\n android:layout_below="@id/rlTopNumara"\n android:padding="16dp" >\n\n <ImageView\n android:id="@+id/ivOnNumara1DateTop"\n android:layout_width="wrap_content"\n android:layout_marginRight="16dp"\n android:layout_height="wrap_content"\n android:layout_alignParentLeft="true"\n android:layout_alignParentTop="true"\n android:padding="8dp"\n android:src="@drawable/on_numara" />\n\n <TextView\n android:id="@+id/tvRandomIdOnNumara1"\n android:layout_width="wrap_content"\n android:layout_height="wrap_content"\n android:layout_alignParentTop="true"\n android:layout_toRightOf="@id/ivOnNumara1DateTop"\n android:text="@string/draw_date_" />\n\n <Spinner\n android:id="@+id/spinnerOnNumara1Numbers"\n android:layout_toRightOf="@id/ivOnNumara1DateTop"\n android:layout_width="wrap_content"\n android:layout_height="wrap_content"\n …Run Code Online (Sandbox Code Playgroud) 请看我的MainActivity.java并告诉我为什么我得到以下错误
The method addConnectionCallbacks(GoogleApiClient.ConnectionCallbacks) in the type GoogleApiClient.Builder is not applicable for the arguments (MainActivity)
package com.example.myapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
public class MainActivity extends Activity {
private GoogleApiClient mGoogleApiClient ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
buildGoogleApiClient();
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this) …Run Code Online (Sandbox Code Playgroud) 我使用EasyPermissions从谷歌库来处理Android上6.第一次权限我按一下按钮,捕捉图像,它要求我给权限CAMERA和WRITE_EXTERNAL_STORAGE.
在我接受了两个权限应用程序崩溃并显示错误消息后,您可以在下面看到:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.debug, PID: 22768
java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=123, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.example.debug/com.example.camera.CameraActivity}: java.lang.RuntimeException: Cannot execute non-void method openCamera
at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: Cannot execute non-void method openCamera
at pub.devrel.easypermissions.EasyPermissions.runAnnotatedMethods(EasyPermissions.java:229)
at pub.devrel.easypermissions.EasyPermissions.onRequestPermissionsResult(EasyPermissions.java:186)
at com.example.camera.CameraActivity.onRequestPermissionsResult(CameraActivity.java:243)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:6553)
at android.app.Activity.dispatchActivityResult(Activity.java:6432)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
at …Run Code Online (Sandbox Code Playgroud) 我对 css 和 android 很陌生。我正在尝试在网络视图中加载要点,但是当我使用时代码的缩进没有出现当webview.loadData(content, "text/html", "utf-8");我使用时它运行良好webview.loadUrl(url);,但我想要前一个。我在这里错过了一些大事吗?哦,缩进是通过 css property 来体现的white-space: pre;。这是我的代码:
final WebView webview = (WebView)getActivity().findViewById(R.id.algoView);
webview.getSettings().setJavaScriptEnabled(true);
//webview.loadUrl("https://gist.github.com/tanaykumarbera/c9f7f3e7490a1c002649/" ); // works perfectly
AsyncHttpClient client = new AsyncHttpClient();
client.get("https://gist.github.com/tanaykumarbera/c9f7f3e7490a1c002649", new AsyncHttpResponseHandler() {
@Override
public void onStart() {
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] res) {
String data="";
ByteArrayInputStream b = new ByteArrayInputStream(res);
String response = "";int c;
while( (c = b.read()) != -1) {
response += Character.toString((char) c);
}
webview.loadData(response, "text/html", "utf-8"); …Run Code Online (Sandbox Code Playgroud) 对于Leanback BrowseFragment,默认情况下屏幕左侧有一个搜索视图.是一种更改默认图标SearchOrbView或隐藏它的方法.
https://cdn-images-1.medium.com/max/800/1*oIFbcdjYrIqxU55-B23tjA.gif