For the vast majority of situations, preexisting keyboard layouts are more than adequate. After all, most input fields in most apps require the input of letters or numbers, and pretty much all aftermarket keyboard solutions have adequate layouts for both situations. However, if you're authoring an app that requires a more purpose-built keyboard, the standard layouts may no longer suffice.

XDA Senior Member SimplicityApks recently created a math analysis tool called FunctionCapture. In creating his app, he quickly found that requiring users to use the default keyboard layouts would prove too cumbersome. Instead, he decided to create his own keyboard layout, tailored for the functions required by his app.

After learning how to create a custom layout, SimplicityApks then shared the instructions in an easily comprehensible manner. Much of the guide is based on a previously created tutorial by developer Maarten Pennings, which the OP has then expanded to include why you perform each of the steps. And to make the overall look match the theme of your app, SimplicityApks has also included a guide (second post) on how to theme your newly created keyboard, so that it matches the overall look and feel of your app.

If you are designing an app that requires non-standard user input, you may want to look into using a custom soft keyboard layout. To learn how to implement this in your own app, head over to the tutorial thread.