在我的一个,我Fragments有一个我从父母打电话的方法Activity.这个方法没什么特别的,它只是将我滚动ListView到一个位置.
public void scrollToSomething() {
mListView.smoothScrollToPosition(The position I supply);
}
Run Code Online (Sandbox Code Playgroud)
当我最初调用这个方法时,它就像我期望的那样工作,但是当我旋转我的设备并再次调用它时,我会NullPointerException从我的设备中抛出一个ListView.我很遗憾为什么会这样.我试过打电话setRetainInstance(true).ListView在调用方法之前我已经尝试检查我是否为null,如果是,那么我再次初始化它,但这也不起作用.我试过onCreateView用几种不同的方式改变我,想想那里可能出现了问题.
onCreateView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
/* The View for the fragment's UI */
final ViewGroup mRootView = (ViewGroup)inflater.inflate(R.layout.fragment_list_base,
container, false);
/* Initialize our ListView */
mListView = (ListView)mRootView.findViewById(R.id.fragment_list_base);
return mRootView;
}
Run Code Online (Sandbox Code Playgroud)
该Fragment附连到ViewPager使用简单FragmentStatePagerAdapter.我已经仔细查看onDestroy了我Fragment和父母的方法,Activity看看我是否正在调用可能导致错误的内容,但没有什么突出的.我不确定我遇到的是某种错误,或者我只是忽略了什么.任何帮助或建议都会很大.我不完全确定还有什么要补充的,因为我只是为什么会发生这种情况而迷失方向,但如果有人有问题,我会发布您认为合适的任何代码.
我有一个应用程序,它使用首选项活动来设置一些用户设置.我一整天都想弄清楚这一点.我试图在用户按下编辑文本首选项对象时设置警告对话框的主题.将打开一个对话框,用户可以设置共享首选项.弹出对话框:

我希望文字为绿色.我希望分频器绿色.线条和光标绿色.
这就是我到目前为止所拥有的.
<style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">
<item name="android:background">@color/text_green</item>
<item name="android:textColor">@color/text_green</item>
</style>
Run Code Online (Sandbox Code Playgroud)
有人可以指出我正确的方向或可能分享一些代码.我迷路了.我一直在网上冲浪,以寻找一天中的大部分时间.提前致谢.
我有两个按钮,每个按钮有一个上下文菜单,但我不确定如何更改第二个菜单中的菜单项.我的代码只显示我的第一个按钮的项目.
Button Button1 = (Button) findViewById(R.id.Button1);
registerForContextMenu(Button1);
Button Button2 = (Button) findViewById(R.id.Button3);
registerForContextMenu(Button2);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Select Notification");
menu.add(0, v.getId(), 0, "Algebraic");
menu.add(0, v.getId(), 0, "Knuckle Train");
menu.add(0, v.getId(), 0, "In My Element ");
menu.add(0, v.getId(), 0, "Let's Get This Party");
menu.add(0, v.getId(), 0, "Shmowzow");
menu.add(0, v.getId(), 0, "What the Jug");
menu.add(0, v.getId(), 0, "Word to Your Mother");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="Algebraic"){function1(item.getItemId());}
else if(item.getTitle()=="Knuckle Train"){function2(item.getItemId());}
else …Run Code Online (Sandbox Code Playgroud) 您可以使用Genymotion更改IMEI吗?有没有办法执行这些任务?

在我的中ActionBar,我有一个MenuItem属性showAsAction="always",如下图所示.根据用户与服务器的连接,我将更改项目的文本和颜色.

目前,我可以非常轻松地更改项目的文本onPrepareOptionsMenu(...):
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem item = menu.findItem(R.id.action_connection);
if(mIsConnected) {
item.setTitle(R.string.action_connected);
} else {
item.setTitle(R.string.action_not_connected);
}
return super.onPrepareOptionsMenu(menu);
}
Run Code Online (Sandbox Code Playgroud)
这很有效,如果可能的话,我也希望在这里更改文本的颜色.我看过很多关于如何将所有溢出项目或标题更改为ActionBar自身的文章,但没有关于改变单个行动项目的任何内容.当前颜色设置为xml,我想动态更改它.
我正在尝试在我的应用程序中创建一个导航抽屉,而没有 ActionBar。我之前在样式中使用 NoActionBar 主题的尝试有效,但现在我无法滑动以打开导航菜单。我需要这样的东西:

我该怎么办?
我有兴趣对特定类型的所有专辑进行查询.通过使用Android,可以轻松地对特定艺术家的专辑执行类似的查询MediaStore.Audio.Artists.Albums.getContentUri,但就查询类型而言,MediaStore.Audio.Genres.Members.getContentUri是提供的最佳方式,但这用于从类型中返回歌曲.
您可以在执行Genres.Members查询后轻松返回每个类型成员的MediaStore.Audio.Genres.Members.ALBUM相册名称,然后使用,返回相册名称,但这仅在您显示歌曲时才有用.
是否有某些选择我只能从一个类型中返回专辑,或者也许是Uri我可以使用的特殊专辑?我没有找到任何关于此的文档,所以如果有任何人有任何信息,将非常感谢.
这是我的导航drawer_main的xml架构...我必须将用户图像放在上面的列表视图中,其他数据通过第二列表视图,就像soundcloud一样.但我在导航抽屉按钮中得到第二个listview,并通过移动边缘我得到第一个抽屉..帮我结合两个XML代码
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/content_frame"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/linerlayout_drawer"
android:layout_height="match_parent"
android:layout_width="240dp"
android:layout_gravity="start"
android:background="@color/white"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:layout_weight="1"/>
<ListView
android:id="@+id/listview_drawer"
android:layout_height="match_parent"
android:layout_width="240dp"
android:layout_gravity="start"
android:background="@color/white"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:layout_weight="1" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
如果我将它们包装在线性布局中则会出错
04-08 21:08:36.605: E/AndroidRuntime(9373): FATAL EXCEPTION: main
04-08 21:08:36.605: E/AndroidRuntime(9373): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ZDevelopers.Workmania/com.ZDevelopers.Workmania.MainActivity}: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
04-08 21:08:36.605: E/AndroidRuntime(9373): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
04-08 21:08:36.605: E/AndroidRuntime(9373): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
04-08 21:08:36.605: E/AndroidRuntime(9373): at android.app.ActivityThread.access$700(ActivityThread.java:159)
04-08 21:08:36.605: E/AndroidRuntime(9373): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
04-08 21:08:36.605: …Run Code Online (Sandbox Code Playgroud) 我的活动中有一个搜索栏.在按钮事件中,当我转到另一个活动然后使用后退按钮时,搜索栏的值设置在用户离开它的位置.当用户回到搜索栏活动时,我想重置搜索栏.我怎样才能实现它?谢谢
public void onClick(View v) {
if (seek.getProgress > 0) {
// do something
}
}
Run Code Online (Sandbox Code Playgroud) 我试图改变动作栏中字幕的颜色,但它不会改变.
这是截图.

这是styles.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:subtitleTextStyle">@style/MyActionBar.TitleTextStyle</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/actionbarBackground</item>
<item name="android:tabStripEnabled">true</item>
<item name="backgroundSplit">@color/white</item>
</style>
<style name="MyActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">
<item name="android:textColor">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我想将我的图像设置为音频mp3文件的专辑封面.我知道相册id,当我更新时,应用程序抛出java.lang.UnsupportedOperationException.
这是我的更新代码..
ContentValues values_art=new ContentValues();
values_art.put(MediaStore.Audio.AlbumColumns.ALBUM_ART, img_path);
int b=getContentResolver().update(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, values_art,MediaStore.Audio.Albums.ALBUM_ID + "=?", new String[]{album_id});
if(b !=0){
Toast.makeText(getApplicationContext(), "Successfuly Image Updated", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(), "Not Image Updated", Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)
我的Logcat:
05-11 00:14:33.063: E/AndroidRuntime(4046): FATAL EXCEPTION: main
05-11 00:14:33.063: E/AndroidRuntime(4046): java.lang.UnsupportedOperationException: Unknown or unsupported URL: content://media/external/audio/albums
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:169)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.content.ContentProviderProxy.update(ContentProviderNative.java:507)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.content.ContentResolver.update(ContentResolver.java:1022)
05-11 00:14:33.063: E/AndroidRuntime(4046): at fsoft.farhad.mediaeditor.AudioTabActivity$4.onClick(AudioTabActivity.java:89)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.view.View.performClick(View.java:4212)
05-11 00:14:33.063: E/AndroidRuntime(4046): at android.view.View$PerformClick.run(View.java:17476) …Run Code Online (Sandbox Code Playgroud) 嗨,我想在谷歌导航栏上拖动时更改我的应用程序徽标.这是我的申请清单:
<application
android:theme="@android:style/Theme.Holo.Light"
android:icon="@drawable/ic_launcher"
android:logo="@drawable/ic_launcher"
android:screenOrientation="portrait"
android:debuggable="false"
android:label="@string/app_name" >
Run Code Online (Sandbox Code Playgroud)

我在android应用程序设计方面绝对有0经验。我的一个朋友要我尝试为他们的应用创建功能,这就是我过去一周一直在尝试的功能。我需要做的前几件事是添加背景图像(完成),添加文本(完成)并添加按钮,该按钮调出菜单(问题)。无需添加按钮,我可以在Android Studio的内置仿真器中运行该应用程序,但是当我添加按钮/ imageButton时,该应用程序将崩溃。在这一点上,我什至没有想过要调出菜单的按钮,那是另一天。我要做的就是让按钮不会崩溃的应用程序。我一直在互联网上寻找教程,文档,甚至在堆栈溢出的地方,但是我什么也找不到。
现在,我什至尚未开始使用Java代码,而仅使用XML代码(请参见下文)。我将发布错误消息(来自android监视器功能的错误消息),并将发布我的设备在工作室中的外观以及在模拟器上显示的消息的图像。如果有人可以帮助我,我将非常感激。
07-17 21:38:05.700 4273-4273/com.example.android.postvu E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.postvu, PID: 4273
java.lang.RuntimeException: Canvas: trying to draw too large(110250000bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
at android.graphics.Canvas.drawBitmap(Canvas.java:1415)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545)
at android.view.View.getDrawableRenderNode(View.java:17314)
at android.view.View.drawBackground(View.java:17250)
at android.view.View.draw(View.java:17062)
at android.view.View.updateDisplayListIfDirty(View.java:16053)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1228)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at …Run Code Online (Sandbox Code Playgroud) android ×13
java ×5
mediastore ×2
xml ×2
button ×1
contextmenu ×1
genymotion ×1
listview ×1
themes ×1
views ×1