So I'm trying to create a popup menu which will popup when user presses on ImageButton.
I'm getting strange force close error on popupMenu.show():
case R.id.action_menu_edit_biljeske_uredi:
linearLayoutDodajBiljeskuBojeIOstalaSranja.setVisibility(View.VISIBLE);
imageButtonBiljeskeDodajBiljeskuBojaPozadine
= (ImageButton) findViewById(R.id.imageButtonBiljeskeDodajBiljeskuBojaPozadine);
imageButtonBiljeskeDodajBiljeskuBojaPozadine.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
PopupMenu popupMenu = new PopupMenu(getApplicationContext(),
imageButtonBiljeskeDodajBiljeskuBojaPozadine);
popupMenu.getMenuInflater().inflate(R.menu.menu_popup_biljeske_boje,
popupMenu.getMenu());
popupMenu.show();
}
});
}
Does anyone know why?
Logcat
04-12 20:22:27.847 24594-24594/com.daroioradecic.studyandexamplannerbydario E/AndroidRuntime:
FATAL EXCEPTION: main
Process: com.daroioradecic.studyandexamplannerbydario, PID: 24594
java.lang.RuntimeException: Failed to resolve attribute at index 6
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:603)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6474)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6642)
at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:741)
at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:685)
at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:62)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.support.v7.view.menu.MenuPopupHelper$MenuAdapter.getView(MenuPopupHelper.java:374)
at android.support.v7.view.menu.MenuPopupHelper.measureContentWidth(MenuPopupHelper.java:223)
at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:157)
at android.support.v7.view.menu.MenuPopupHelper.show(MenuPopupHelper.java:129)
at android.support.v7.widget.PopupMenu.show(PopupMenu.java:216)
at com.daroioradecic.studyandexamplannerbydario.BiljeskeDodajBiljesku$2.onClick(BiljeskeDodajBiljesku.java:106)
at android.view.View.performClick(View.java:4856)
at android.view.View$PerformClick.run(View.java:19956)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5389)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
Menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:icon="#drawable/ic_action_crvena"
android:title=""
android:id="#+id/popupMenuBiljeskeBojeCrvena"/>
<item
android:icon="#drawable/ic_action_ljubicasta"
android:title=""
android:id="#+id/popupMenuBiljeskeBojeLjubicasta"/>
<item
android:icon="#drawable/ic_action_svijetloplava"
android:title=""
android:id="#+id/popupMenuBiljeskeBojeSvijetloPlava"/>
<item
android:icon="#drawable/ic_action_tamnoplava"
android:title=""
android:id="#+id/popupMenuBiljeskeBojeTamnoPlava"/>
<item
android:icon="#drawable/ic_action_zelena"
android:title=""
android:id="#+id/popupMenuBiljeskeBojeZelena"/>
<item
android:icon="#drawable/ic_action_usranozuta"
android:title=""
android:id="#+id/popupMenuBiljeskeBojeUsranoZuta"/>
<item
android:icon="#drawable/ic_action_narancasta"
android:title=""
android:id="#+id/popupMenuBiljeskeBojeNarancasta"/>
<item
android:icon="#drawable/ic_action_siva"
android:title=""
android:id="#+id/popupMenuBiljeskeBojeSiva"/>
</menu>
PopupMenu popupMenu = new PopupMenu(getApplicationContext(), imageButtonBiljeskeDodajBiljeskuBojaPozadine);
Replace getApplicationContext() with YourActivity.this. I think your problem will be solved.
Why getApplicationContext() is not working, visit https://possiblemobile.com/2013/06/context/ for detailed solution.
Related
I've cloned this git depo it's an application that allows you to capture or choose images and save them in a pdf document.
It work fine, but when I tried to integrate in my app module (new project) and clicked on the button to start the activity it crash. I haven't changed anything the Logcat isn't helping either...
Any ideas ?
Note : I already added the activity in my manifest.
Edit : I added the style and layout below
styles
<style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
activity_pdf
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.nabeeltech.capturedoc.imgtopdf.PdfActivity">
<Button
android:id="#+id/btnPdf"
android:layout_width="match_parent"
android:layout_margin="16dp"
android:text="Generate Document"
android:layout_height="wrap_content" />
</LinearLayout>
PdfActivity
Button btn_Pdf = findViewById(R.id.btnPdf);
activity = this;
filename=new Date().toString();
btn_Pdf.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
getImages();
}
});
}
private void getImages() {
Config config = new Config();
config.setToolbarTitleRes(R.string.str_bar_tool);
ImagePickerActivity.setConfig(config);
Intent intent = new Intent(this, ImagePickerActivity.class);
startActivityForResult(intent, INTENT_REQUEST_GET_IMAGES);
}
#Override
protected void onActivityResult(int requestCode, int resuleCode, Intent intent) {
super.onActivityResult(requestCode, resuleCode, intent);
if (requestCode == INTENT_REQUEST_GET_IMAGES && resuleCode == Activity.RESULT_OK) {
ArrayList<Uri> image_uris = intent.getParcelableArrayListExtra(ImagePickerActivity.EXTRA_IMAGE_URIS);
if(image_uris.size()!=0){
ArrayList<String> tempUris = new ArrayList<>();
for (Uri uri : image_uris) {
tempUris.add(uri.getPath());
}
CallBackCreatePdf callBackCreatePdf = new CallBackCreatePdf() {
#Override
public void OnCallBackCreatePdf(String tPath) {
if(tPath!=""){
Toast.makeText(getBaseContext(),"Pdf Created", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getBaseContext(),"Error creating PDF", Toast.LENGTH_LONG).show();
}
}
};
MaterialDialog.Builder builder = new MaterialDialog.Builder(activity)
.title("Creating PDF")
.content("just a moment ...")
.cancelable(false)
.progress(true, 0);
MaterialDialog dialog = builder.build();
AsynCreatePdf asynCreatePdf = new AsynCreatePdf(activity,callBackCreatePdf,dialog,tempUris,"1",("pdf"+(new Date()).getSeconds()));
asynCreatePdf.execute();
}
Log.d(LOG_ACTIVITY, "onActivityResult");
}
}
Here is the stack trace
2020-02-05 16:44:36.884 17311-17311/com.nabeeltech.capturedoc E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nabeeltech.capturedoc, PID: 17311
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nabeeltech.capturedoc/com.gun0912.tedpicker.ImagePickerActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:421)
at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:150)
at com.gun0912.tedpicker.ImagePickerActivity.initView(ImagePickerActivity.java:95)
at com.gun0912.tedpicker.ImagePickerActivity.onCreate(ImagePickerActivity.java:82)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
This Activity already has an action bar supplied by the window decor.
Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set
windowActionBar to false in your theme to use a Toolbar instead.
at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:421)
Need Another theme. At first goto manifest
<activity android:name=".ImagePickerActivity"
android:theme="#style/CustomTheme"
android:screenOrientation="portrait"
/>
Then go to res/values/styles.xml section. Create Theme. Your Theme will be
<style name="CustomTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Fixed. Thanks to #intellij-amiya
I missed another style. I was using
<activity android:name="com.nabeeltech.capturedoc.imgtopdf.PdfActivity"
android:label="#string/title_activity_pdf"
android:theme="#style/MyAppTheme"/>
<activity android:name="com.gun0912.tedpicker.ImagePickerActivity"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar"
android:screenOrientation="portrait"
/>
So I replaced ImagePickerActivity with
android:theme="#style/AppTheme_picker"
Now it works.
I have a Options menu with sub-item menus
My app crashes when I click on the option menu, but I can't decrypt logs
I want to have a option button who open 3 option menu subitems
I have checked few tutorials but I can't see where i'm wrong
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="#+id/search_button_main_activity"
android:icon="#drawable/search_button"
android:title="#string/search_button"
app:showAsAction="ifRoom"/>
<item
android:id="#+id/notifications_button"
android:title="#string/notifications_button"
app:showAsAction="never" />
<item
android:id="#+id/help_button"
android:orderInCategory="100"
android:title="#string/help_button"
app:showAsAction="never" />
<item
android:id="#+id/about_button"
android:orderInCategory="100"
android:title="#string/about_button"
app:showAsAction="never" />
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_activity_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.search_button_main_activity:
this.launchSearchActivity();
return true;
case R.id.notifications_button:
Toast.makeText(this, "This will launch notification feature", Toast.LENGTH_SHORT).show();
return true;
case R.id.about_button:
Toast.makeText(this, "This will launch about feature", Toast.LENGTH_SHORT).show();
return true;
case R.id.help_button:
Toast.makeText(this, "This will launch help feature", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
here's error message :
2019-07-01 16:12:46.581 com.matt.android.mynews E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.matt.android.mynews, PID: 7624
android.view.InflateException: Binary XML file line #51: Binary XML file line #51: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #51: Error inflating class TextView
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 4: TypedValue{t=0x2/d=0x1010099 a=1}
at android.content.res.TypedArray.getColor(TypedArray.java:461)
at android.widget.TextView.<init>(TextView.java:771)
at android.widget.TextView.<init>(TextView.java:704)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:87)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:83)
at android.support.v7.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:177)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:102)
at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:886)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:886)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.inflate(LayoutInflater.java:522)
at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
at android.support.v7.view.menu.MenuAdapter.getView(MenuAdapter.java:94)
at android.support.v7.view.menu.MenuPopup.measureIndividualMenuWidth(MenuPopup.java:161)
at android.support.v7.view.menu.StandardMenuPopup.tryShow(StandardMenuPopup.java:174)
at android.support.v7.view.menu.StandardMenuPopup.show(StandardMenuPopup.java:208)
at android.support.v7.view.menu.MenuPopupHelper.showPopup(MenuPopupHelper.java:290)
at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:177)
at android.support.v7.widget.ActionMenuPresenter$OpenOverflowRunnable.run(ActionMenuPresenter.java:806)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6228)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Logs can't tell me where the crash come from
The error you're getting is not from the menu. It's most probably from the layout you're calling in launchSearchActivity.
As I understand what you want is something like below
You can have a menu like that with the xml given below(Please change the drawables, names and ids as you want)
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item
android:id="#+id/action_rate" android:title="#string/action_rate"
android:icon="#drawable/ic_favorite_border_black_24dp" app:showAsAction="always|withText"/>
<item
android:icon="#drawable/ic_more_vert_black_24dp"
android:title="More"
app:showAsAction="always">
<menu>
<item android:id="#+id/action_contact_us" android:icon="#drawable/ic_email_black_24dp"
android:title="#string/action_about"
android:orderInCategory="102" app:showAsAction="never"/>
<item android:id="#+id/action_moreapps" android:icon="#drawable/ic_shop_black_24dp"
android:title="#string/action_more_apps"
android:orderInCategory="103" app:showAsAction="never"/>
<item android:id="#+id/action_exit" android:icon="#drawable/ic_close_black_24dp"
android:title="#string/action_exit"
android:orderInCategory="107" app:showAsAction="never"/>
</menu>
</item>
I am trying to display a Popup menu on the click of an action bar Icon.
The problem is that I get a forced close of the app and the Popup menu does not display. What is wrong with my code? Thank you for your help.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_action, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
Toast.makeText(getApplicationContext(), "ItemSelected = " + item, Toast.LENGTH_SHORT).show();
case R.id.action_sort:
showPopup(item.getActionView());
}
return super.onOptionsItemSelected(item);
}
public void showPopup(View v) {
PopupMenu popup = new PopupMenu(this, v);
Toast.makeText(getApplicationContext(), "showPopup = " + popup, Toast.LENGTH_SHORT).show();
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.popup_menu, popup.getMenu());
popup.show();
}
menu_action.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".FileManagerActivity">
<item android:id="#+id/action_sort" android:title="#string/action_sort" android:icon="#drawable/ic_sort"
android:showAsAction="always" />
<item android:id="#+id/action_settings" android:title="#string/action_settings"
app:showAsAction="never" />
<item android:id="#+id/action_help" android:title="#string/action_help"
app:showAsAction="never" />
</menu>
popup_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/opt1"
android:icon="#drawable/ic_sort"
android:title="Change Picture" />
<item
android:id="#+id/opt2"
android:icon="#drawable/ic_fast_forward"
android:title="Change Password" />
<item
android:id="#+id/opt3"
android:icon="#drawable/ic_fast_rewind"
android:title="Sign Out" />
</menu>
Logcat:
02-28 13:04:45.353 18838-18838/com.test.audio E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.test.audio, PID: 18838
java.lang.IllegalStateException: MenuPopupHelper cannot be used without an anchor
at android.support.v7.internal.view.menu.MenuPopupHelper.show(MenuPopupHelper.java:126)
at android.support.v7.widget.PopupMenu.show(PopupMenu.java:193)
at com.test.audio.TouchActivity.showPopup(TouchActivity.java:5340)
at com.test.audio.TouchActivity.onOptionsItemSelected(TouchActivity.java:5270)
at android.app.Activity.onMenuItemSelected(Activity.java:2885)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1133)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894)
at android.widget.ActionMenuView.invokeItem(ActionMenuView.java:587)
at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:141)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
don't pass MenuItem as View cause it s not.
so it s better to cast it as view like this
View menuItemView = findViewById(R.id.menu_overflow); // SAME ID AS MENU ID
PopupMenu popupMenu = new PopupMenu(this, menuItemView);
popupMenu.inflate(R.menu.counters_overflow);
// And define click listener here.
popupMenu.show();
Source
I have been trying using custom title bar in my activity. Following is the code i have used
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
if ( customTitleSupported ) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);
}
final TextView txtTitle = (TextView) findViewById(R.id.txtTitle);
if ( txtTitle != null ) {
txtTitle.setText("PikMyBox - Welcome to PikMyBox");
}
setContentView(R.layout.activity_main);
}
custom_title_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txtTitle"
android:layout_alignParentLeft="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txtCustomText"
android:layout_alignParentRight="true"/>
</RelativeLayout>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorSplash</item>
<item name="android:windowNoTitle">true</item>
</style>
Manifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
-----
I m getting the following error when activity executed
android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:302)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2975)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3241)
at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1821)
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:363)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312)
at android.support.v7.app.AppCompatDelegateImplV7.findViewById(AppCompatDelegateImplV7.java:229)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:184)
at com.kommlabs.pikmybox.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5447)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
How can i solve this problem ?
Change android:windowNoTitle to false in your styles.xml.
Your setContentView(R.layout.activity_main); is below final TextView txtTitle = (TextView) findViewById(R.id.txtTitle); ie why you are getting exception.You are initilizing the view before it is been created.
Change it to
setContentView(R.layout.activity_main);
final TextView txtTitle = (TextView) findViewById(R.id.txtTitle);
Also in case of your exception with custom title bar use this style
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">false</item>
</style>
As suggested here https://stackoverflow.com/a/27410003/3111083
I am using EditText in my app, I see during copy/paste operations sometimes it crashes the app. Unfortunately I couldn't replicate the error or never encountered it but there are good number of people experiencing it.
I am attaching the Log :
Fatal Exception: java.lang.IndexOutOfBoundsException: 98, -81
at android.text.PackedIntVector.deleteAt(PackedIntVector.java:218)
at android.text.DynamicLayout.reflow(DynamicLayout.java:308)
at android.text.DynamicLayout.access$000(DynamicLayout.java:41)
at android.text.DynamicLayout$ChangeWatcher.reflow(DynamicLayout.java:650)
at android.text.DynamicLayout$ChangeWatcher.onSpanChanged(DynamicLayout.java:679)
at android.text.SpannableStringBuilder.sendSpanChanged(SpannableStringBuilder.java:1019)
at android.text.SpannableStringBuilder.sendToSpanWatchers(SpannableStringBuilder.java:601)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:532)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:465)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:38)
at android.widget.TextView.paste(TextView.java:9130)
at android.widget.TextView.onTextContextMenuItem(TextView.java:8940)
at com.paprbit.dcoder.ui.widget.DcoderEditor.onTextContextMenuItem(DcoderEditor.java:881)
at android.widget.Editor$ActionPopupWindow.onClick(Editor.java:3047)
at android.view.View.performClick(View.java:4825)
at android.view.View$PerformClick.run(View.java:20144)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5537)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
Here is my code :
#Override
public boolean onTextContextMenuItem(
final int id) {
boolean handled = false;
switch (id) {
case CodeNow.ID_UNDO:
handled = true;
if (canUndo()) {
undo();
}
break;
case CodeNow.ID_REDO:
handled = true;
if (canRedo()) {
redo();
}
break;
}
if (handled) {
return true;
} else {
return super.onTextContextMenuItem(id);
}
}
My xml Code Where i added the edittext
<com.paprbit.dcoder.ui.widget.DcoderEditor
android:id="#+id/et_code_content"
style="?editTextDcoderEditor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:textCursorDrawable="#drawable/cursor" />
and style for this edittext
<style name="EditTextDcoderEditor">
<item name="android:textSize">15sp</item>
<item name="android:layout_marginTop">2dp</item>
<item name="android:selectAllOnFocus">false</item>
<item name="android:imeOptions">flagNoExtractUi</item>
<item name="android:inputType">textNoSuggestions|textMultiLine</item>
<item name="android:paddingLeft">1dp</item>
<item name="android:paddingTop">1dp</item>
<item name="android:paddingBottom">1dp</item>
<item name="android:paddingRight">10dp</item>
<item name="android:isScrollContainer">true</item>
</style>